How to retrieve the Category with tags

View: New views
2 Messages — Rating Filter:   Alert me  

How to retrieve the Category with tags

by Benoit Pironet :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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
template_list@...
http://lists.jahia.org/cgi-bin/mailman/listinfo/template_list

Re: How to retrieve the Category with tags

by Benoit Pironet :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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-bounces@... on behalf of PIRONET BenoƮt
Sent: Tue 24/06/2008 17:00
To: template_list@...
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
template_list@...
http://lists.jahia.org/cgi-bin/mailman/listinfo/template_list



_______________________________________________
template_list mailing list
template_list@...
http://lists.jahia.org/cgi-bin/mailman/listinfo/template_list

winmail.dat (5K) Download Attachment