You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Dan Klco (JIRA)" <ji...@apache.org> on 2012/12/31 22:14:12 UTC

[jira] [Updated] (SLING-2648) Add Resource Access Tags

     [ https://issues.apache.org/jira/browse/SLING-2648?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dan Klco updated SLING-2648:
----------------------------

    Attachment: SLING-2648-Add-Resource-Access-Tags-With-Tests-And-Functions.diff

Attached a new patch with jUnit Tests and Expression Language functions for listing children and getting a resource. 

These expressions allow you to do the following:

    <c:set var="currentResource" value="${sling:getResource(resourceResolver,'/etc')}" />
    <c:forEach var="child" items="${sling:listChildResources(currentResource)}">
        <c:if test="${child.name != 'jcr:content'}">
            <sling:getResource var="pageContent" path="${child.path}/jcr:content" />
            <sling:adapt adaptable="${pageContent}" adaptTo="org.apache.sling.api.resource.ValueMap" var="childProperties" />
            <sling:getProperty key="jcr:title" defaultValue="${child.name}" var="title" properties="${childProperties}" />
            <li><a href="${child.path}.html">Title: ${title}</a></li>
        </c:if>
    </c:forEach>
                
> Add Resource Access Tags
> ------------------------
>
>                 Key: SLING-2648
>                 URL: https://issues.apache.org/jira/browse/SLING-2648
>             Project: Sling
>          Issue Type: New Feature
>          Components: Scripting
>    Affects Versions: Scripting JSP-Taglib 2.1.8
>            Reporter: Dan Klco
>              Labels: patch, scripting, taglib
>         Attachments: SLING-2648-Add-Resource-Access-Tags.diff, SLING-2648-Add-Resource-Access-Tags.diff, SLING-2648-Add-Resource-Access-Tags-With-Tests-And-Functions.diff, SLING-2648-Document-Tags.diff
>
>
> It would be really nice to be able to access resources through tags rather than having to use Scriptlet for even basic Resource iteration.  I've created a patch for adding tags to:
>  - Get a Resource
>  - List Child Resources
>  - Adapt adaptables to other classes
>  - Get properties from ValueMaps (with default values)
> With these new tags, you will be able to do things like create an entire navigation without scriptlet:
> <ul>
>     <sling:getResource var="currentResource" path="/libs" />
>     <sling:listChildren var="children" resource="${currentResource}" />
>     <c:forEach var="child" items="${children}">
>         <c:if test="${child.name != 'jcr:content'}">
>             <sling:getResource var="pageContent" path="${child.path}/jcr:content" />
>             <sling:adapt adaptable="${pageContent}"  adaptTo="org.apache.sling.api.resource.ValueMap" var="childProperties" />
>             <sling:getProperty key="jcr:title" defaultValue="${child.name}" var="title" properties="${childProperties}" />
>             <li><a href="${child.path}.html">Title: ${title}</a></li>
>         </c:if>
>     </c:forEach>
> </ul>

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira