Discussion:
How to retrieve the Category with tags
PIRONET Benoît
2008-06-24 15:00:30 UTC
Permalink
Hi,

I'd like to retrieve the category of a container using the tags in Jahia 5.0.3.

An acceptable way would be to retrieve the ObjectKey of the Container(bean?) and use a scriptlet/custom tag to loops through categories and select the first one.

Is there a way ? perhaps using the expression languages ?

Thank you in advance,

Benoit Pironet
PIRONET Benoît
2008-06-25 07:36:42 UTC
Permalink
I reply to my own subject since I found a solution.

If someone has a better solution, I'm ok to use it :)


First I declare my bean :
<bean:define id="newsContainer" name="newsContainer" type="org.jahia.data.beans.ContainerBean"/>

Then I get the objectKey of the contentContainer:
newsContainer.getContentContainer().getObjectKey()

And I use the normal way to get a category:
Set categories = Category.getObjectCategories(newsContainer.getContentContainer().getObjectKey());
Iterator i = categories.iterator();
while(i.hasNext()) {
Category cat = (Category)i.next();
out.println(cat.getTitle(jParams.getLocale()));
break; // Display only first category
}


Here is the complete solution:

<content:containerList name="newsContainer" id="newsContainerList">
<content:container id="newsContainer">
<bean:define id="newsContainer" name="newsContainer" type="org.jahia.data.beans.ContainerBean"/>
<div class="news-entry">
<content:pageField valueId="newsLink" name="newsLink"/>
<div class="date">
<content:dateField name="newsPublicationDate" valueId="newsPublicationDate" display="true"/>
</div>
<div class="category">
<%
Set categories = Category.getObjectCategories(newsContainer.getContentContainer().getObjectKey());
Iterator i = categories.iterator();
while(i.hasNext()) {
Category cat = (Category)i.next();
out.println(cat.getTitle(jParams.getLocale()));
break; // Display only first category
}
%>
</div>
</div>
</content:container>
</content:containerList>


As I said, if someone has comments or better solution, I'm happy to get it.


Benoit Pironet


-----Original Message-----
From: template_list-***@jahia.org on behalf of PIRONET Benoît
Sent: Tue 24/06/2008 17:00
To: ***@jahia.org
Subject: [template_list] How to retrieve the Category with tags


Hi,

I'd like to retrieve the category of a container using the tags in Jahia 5.0.3.

An acceptable way would be to retrieve the ObjectKey of the Container(bean?) and use a scriptlet/custom tag to loops through categories and select the first one.

Is there a way ? perhaps using the expression languages ?

Thank you in advance,

Benoit Pironet

Loading...