Hi Kevin,
the Template Developer Guide says that you can retrieve this object from
request attribute. You just did not use the correct attribute name,
which is also correctly documented in the Template Developer Guide.
You could perfectly retrieve the object with:
request.getAttribute("currentSite")
the pageContext.findAttribute is doing that internally, as it simply
searches up the scopes.
You do not have to use scriptlets at all. The currentSite bean can be
accessed by JSTL or Struts tags.
There is also an example in the Template Developer Guide, like this:
<c:if test="${currentPage.id == currentSite.homepageID)”>
</c:if>
Along with the Template Developer Guide we are also developing example
templates - called doc_templates, which can be found in our SVN (Check
here: http://svn.jahia.org/). These should finally cover all chapters
and examples in the Template Deverloper Guide. There are multiple
examples to show how to develop templates without scriptlets. Notice
that Jahia 5.0.3 only support JSTL 1.0, but you could easily change it
to use a newer version (see current 5.x Template Developer Guide, page
20). So your example with the iteration could be solved with tags.
I don't know your use case, what exactly you have to do. Is the
"fooContainerList" existing on different pages throughout your site?
I think you can do the same what you want to do here with the
ContainerFilterByContainerDefinition. It is true that it is not
documented yet, but you can see how it works in
corporate_portal_templates_v2\src\jsp\box\lastNews.inc
A discussion on it is in our mailing list:
http://article.gmane.org/gmane.comp.cms.jahia.template/1587/match=containerfilterbycontainerdefinition
Notice, that right now we are working on new taglibs, so for all this
container searchers/filters/sorters you also won't need scriptlets
anymore. It will also be better documented and out with Jahia 5.1.
Bye,
Benjamin
On 30.01.2008 15:49 Kevin wrote:
> Hi Benjamin,
>
> Thanks for the reply.
> I meant to post a follow up yesterday but life got in the way.
>
> Actually, you are spot on. That did the trick. It's just the
> documentation didn't indicate that approach and I guess I've been
> spending too much time in the MVC world that pageContext is not
> something I've used as much lately. I don't do scriptlets.
>
> For anyone who might benefit from this, here's a code snippet of how
> one might pull data from a container located several layers deep.
>
> This uses the getLightContainerLists method that the documentation
> indicates performs better. Unfortunately, there's not taglib for this
> (that I can see). Jahia needs to pick up the pace on this so we can
> minimize our use of scriptlets (not a best practice).
>
> <%
> // not so fun jahia api here
> SiteBean currentSite = (SiteBean) pageContext.findAttribute("currentSite");
> List allNewsLists = currentSite.getLightContainerLists("fooContainerList");
> for (Iterator iter = allNewsLists.iterator(); iter.hasNext();) {
> ContainerListBean containerListBean = (ContainerListBean) iter.next();
> List myContainerList = containerListBean.getContainers();
> //System.out.println("myContainerList size = " +
> myContainerList.size());
> // for us, we only allow one instance of fooContainerList, grab the
> first one
> ContainerBean containerBean = (ContainerBean)myContainerList.get(0);
> // ugly here, just a proof of concept
> %>
> title=<%=containerBean.getFieldValue("mTitle")
> %>,summary=<%=containerBean.getFieldValue("mSummary") %>
> <%
> //System.out.println("mTitle = " +
> containerBean.getFieldValue("mTitle"));
> //System.out.println("mTitle = " +
> containerBean.getFieldValue("mSummary"));
> }
> %>
> _______________________________________________
> 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