Jahia in English > News module jsp...

0 (0 Good)
0 (0 Bad)

News module jsp file edit

by  Js »  2017/06/13 09:07

Hello, I want to change the news module, so when clicking on the title it did not bring user to specified news entry page, but to parent page were news module is embedded. The same should happen when user clicks on the news article in “Latest news retrieving ” module. I would be very grateful if somebody would help me with the code snippet for the News.jsp file. I understand that I need to edit the URL path here, but due to limited coding knowledge, I can’t figure out how to Mit freundlichen Grüßen / Best regards
Js
Number of messages  1
Not registered
0 (0 Good)
0 (0 Bad)

Re: News module jsp file edit

by  jordannroussel »  2017/06/13 09:20

Hello,

The taglib "jcr" has a method called "getParentOfType" which could help you retrieving a parent node of a given nodetype. You then need to construct a link based on the retrieved node.

A code similar to the following should do the trick :

<c:set var="parentPageNode" value="${jcr:getParentOfType(currentNode, 'jnt:page')}"/>
<c:url var="parentPageUrl" value="${url.base}${parentPageNode.path}.html"/>
<a href="${parentPageUrl}">Link to parent page of the news node</a>

 

Do not hesitate to tell me if it is not working properly.

Regards

  • Re: News module jsp file edit
    2017/06/13 09:21

    jordannroussel <p>Hello,</p> <p>The taglib &quot;jcr&quot; has a method called &quot;getParentOfType&quot; which could help you retrieving a parent node of a given nodetype. You then need to construct a link based on the retrieved node.</p> <p>A code similar to the following should do the trick :</p> <pre style="color: rgb(0, 0, 0); font-family: Menlo;"> <span style="background-color:#f7faff;">&lt;</span><span style="color:#660e7a;background-color:#f7faff;font-weight:bold;">c</span><span style="color:#000080;background-color:#f7faff;font-weight:bold;">:set </span><span style="color:#0000ff;background-color:#f7faff;font-weight:bold;">var</span><span style="color:#008000;background-color:#f7faff;font-weight:bold;">=&quot;parentPageNode&quot; </span><span style="color:#0000ff;background-color:#f7faff;font-weight:bold;">value</span><span style="color:#008000;background-color:#f7faff;font-weight:bold;">=&quot;</span><span style="color:#000080;background-color:#f7faff;font-weight:bold;">${</span><span style="background-color:#f7faff;">jcr:getParentOfType(currentNode, </span><span style="color:#008000;background-color:#f7faff;font-weight:bold;">&#39;jnt:page&#39;</span><span style="background-color:#f7faff;">)</span><span style="color:#000080;background-color:#f7faff;font-weight:bold;">}</span><span style="color:#008000;background-color:#f7faff;font-weight:bold;">&quot;</span><span style="background-color:#f7faff;">/&gt;</span> <span style="background-color:#f7faff;">&lt;</span><span style="color:#660e7a;background-color:#f7faff;font-weight:bold;">c</span><span style="color:#000080;background-color:#f7faff;font-weight:bold;">:url </span><span style="color:#0000ff;background-color:#f7faff;font-weight:bold;">var</span><span style="color:#008000;background-color:#f7faff;font-weight:bold;">=&quot;parentPageUrl&quot; </span><span style="color:#0000ff;background-color:#f7faff;font-weight:bold;">value</span><span style="color:#008000;background-color:#f7faff;font-weight:bold;">=&quot;</span><span style="color:#000080;background-color:#f7faff;font-weight:bold;">${</span><span style="background-color:#f7faff;">url.base</span><span style="color:#000080;background-color:#f7faff;font-weight:bold;">}${</span><span style="background-color:#f7faff;">parentPageNode.path</span><span style="color:#000080;background-color:#f7faff;font-weight:bold;">}</span><span style="color:#008000;background-color:#f7faff;font-weight:bold;">.html&quot;</span><span style="background-color:#f7faff;">/&gt;</span> <span style="background-color:#efefef;">&lt;</span><span style="color:#000080;background-color:#efefef;font-weight:bold;">a </span><span style="color:#0000ff;background-color:#efefef;font-weight:bold;">href=</span><span style="color:#008000;background-color:#efefef;font-weight:bold;">&quot;</span><span style="color:#000080;background-color:#f7faff;font-weight:bold;">${</span><span style="background-color:#f7faff;">parentPageUrl</span><span style="color:#000080;background-color:#f7faff;font-weight:bold;">}</span><span style="color:#008000;background-color:#efefef;font-weight:bold;">&quot;</span><span style="background-color:#efefef;">&gt;</span>Link to parent page of the news node<span style="background-color:#efefef;">&lt;/</span><span style="color:#000080;background-color:#efefef;font-weight:bold;">a</span><span style="background-color:#efefef;">&gt;</span></pre> <p>&nbsp;</p> <p>Do not hesitate to tell me if it is not working properly.</p> <p>Regards</p>

  • Number of messages  13
    Registration date Jun 13, 2017
    0 (0 Good)
    0 (0 Bad)

    Re: Re: News module jsp file edit

    by  js »  2017/06/23 08:34

    Thank you for your help,

    I followed your instructions and I was able to create the needed view, it work but it bring me to the overall parent page, and not the parent page were News module is embeded.

    This is my code, maybe you can point out what I did wrong?

    <%@ taglib prefix="jcr" uri="http://www.jahia.org/tags/jcr" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
    <%@ taglib prefix="utility" uri="http://www.jahia.org/tags/utilityLib" %>
    <%@ taglib prefix="template" uri="http://www.jahia.org/tags/templateLib" %>
    <%@ taglib prefix="functions" uri="http://www.jahia.org/tags/functions" %>

    <template:addResources type="css" resources="news.css"/>
    <c:set var="language" value="${currentResource.locale.language}"/>
    <fmt:setLocale value="${language}" scope="session"/>

    <c:set var="newsTitle" value="${currentNode.properties['jcr:title']}"/>
    <c:url var="detailUrl" value="${url.base}${parentPageNode.path}.html"/>


    <fmt:formatDate pattern="dd MMM, yyyy" dateStyle="short" value="${currentNode.properties['date'].time}" var="newsDate"/>

    <h3><a href="${detailUrl}">${newsTitle}</a></h3>
    <small>${newsDate}
        <%-- display tags --%>
        <jcr:nodeProperty node="${currentNode}" name="j:tagList" var="tags"/>
        <c:forEach items="${tags}" var="tag" varStatus="status">
            <c:if test="${status.first}">&nbsp;<fmt:message key="jnt_news.in"/>&nbsp;</c:if>${tag.string}<c:if
                test="${not status.last}">,</c:if>
        </c:forEach>
    </small>

     

     

    js
    Number of messages  2
    Not registered
    Contact
    Share
    Feedback

    Get in touch

    Whether you are a current user or if you are just evaluating Jahia, we are here to help.

    Contact us

    Share this page