Iterate Over Assets

25 views
Skip to first unread message

Zach Calvert

unread,
May 29, 2015, 11:01:42 AM5/29/15
to hippo-c...@googlegroups.com
If I define an asset folder and upload PDF content to it, is there a way to automate retrieving the list of assets in Freemarker based on the folder?  IE if I have PDF "Hello.pdf", "Hello Again.pdf" in asset folder "hello", can I generate a freemarker template that will have all of these items in an automated fashion?  Is it possible to get an index listing for the asset folder?  

Mathijs den Burger

unread,
Jun 1, 2015, 3:53:50 AM6/1/15
to hippo-c...@googlegroups.com
Sure, an HST component can do something like:

  public void doBeforeRender(final HstRequest request, final HstResponse response) {
        request.setAttribute("assetFolders", getAssetBaseBean(request).getFolders());
  }

and then your Freemarker template can traverse the folders somehow and show the document names. For example:

  <#list assetFolders as folder>
    <#list folder.documents as asset>
      ${asset.localizedName}
    </#list>
  </#list>

This will show all asset names in the top-level folders. You can also retrieve a single folder with:

  request.setAttribute("helloFolder", getAssetBaseBean(request).getChildBeansByName("hello", HippoFolderBean.class).get(0));

If you want to be able to traverse the whole asset tree using index pages (like an old-fashioned file tree exposed via Apache) you could create a separate channel [1] (e.g. on a mount "/assets") whose content base is /content/assets. A single _any_ matcher in the sitemap of that channel could then point to an 'index page' that renders all index pages. The HST component of that index page can just use the EssentialsContentComponent [2] instead of the custom code shown before to put the current asset folder on the request. Its Freemarker template can iterate over the documents in that folder and generate an index.

hope this helps,
Mathijs





On Fri, May 29, 2015 at 5:01 PM, Zach Calvert <zach.c...@dynamit.com> wrote:
If I define an asset folder and upload PDF content to it, is there a way to automate retrieving the list of assets in Freemarker based on the folder?  IE if I have PDF "Hello.pdf", "Hello Again.pdf" in asset folder "hello", can I generate a freemarker template that will have all of these items in an automated fashion?  Is it possible to get an index listing for the asset folder?  

--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-c...@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.
Visit this group at http://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages