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

<<winmail.dat>>

_______________________________________________
template_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/template_list

Reply via email to