Re: How to retrieve the Category with tags

PIRONET Benoît <[email protected]> Wed, 25 Jun 2008 09:36:42 +0200
Newsgroups gmane.comp.cms.jahia.template
Message-ID <27112111568D6346939B1DABE49CD100CE89C6@lux-mail.lux.cronos-technologies.com>
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: [email protected] on behalf of PIRONET Benoît
Sent: Tue 24/06/2008 17:00
To: [email protected]
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
_______________________________________________
template_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/template_list

_______________________________________________
template_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/template_list
winmail.dat (application/ms-tnef, 3.7 KB) - not displayed