Skip to main content

Inculde the code fragment based on the section template usage

Comments

3 comments

  • Zendesk API User
    Author: mikula - 2/18/2019 13:23

    As Developer I do not really understand why you would like to do this.
    Is it not possible to add the desired functionallity to the section template you are using?

    0
  • Zendesk API User
    Author: hbarthel - 2/18/2019 14:10

    Hi,

    I can imagine, you want to add CSS or JS for an image gallery only, if a gallery section is in the page. And the answer is "yes, you can". There are, as always, many ways to do so. First: do I understand you correctly? If not please clarify your use case.

    Cheers, Heiko

    0
  • Zendesk API User
    Author: mbergmann - 2/23/2019 22:21

    Hi,

    a usual way is something like the following code:

    $CMS_IF(

      #global.page.getChildren(class("de.espirit.firstspirit.access.store.pagestore.Section"), true).toList

        .filter(section->section.isInOutputIncluded(#global.language))

        .map(section->section.template.uid)

        .filter(templateUid->["one_template_uid","another_uid"].contains(templateUid))

        .size()>0

    )$

    Code to be output if there is at least one "active" section based on one of the given templates.

    $CMS_END_IF$

    This version also supports multiple section uids. Of course you could write the same a little shorter by using a combined condition (&& instead of chained filter/map) but I prefer code like the above because I think it is better readable as it kind of describes the steps.

    You could also start with !#global.page... and use isEmpty() at the end but that little ! is too easy to miss in my opinion.

    Michael

    0

Please sign in to leave a comment.