Search code examples
crafter-cms

How to list all siteItem in a component folder in a ftl template?


In Crafter CMS, I have a list of components under a folder in "Components".

So the structure is:

  • /site/components/folder1/component1.xml
  • /site/components/folder1/component2.xml
  • ...

So what I am trying to do is to list these components and display them in my Crafter site

I have tried this:

<#list siteItemService.getSiteItem("site/components/folder1").getChildItems() ! [] as item>
    <p>${item.title_s}</p>
</#list>

But it does not work. Does anyone has an idea of how to do this?


Solution

  • Ok so I used getSiteTree("/site/components/folder1", 1).getChildItems() instead and now it is working.

    It did not found it in the documentation (https://javadoc.craftercms.org/3.0.27/engine/org/craftercms/engine/model/SiteItem.html).