Skip to main content

Dynamic definition of root in Navigation function

Comments

4 comments

  • Zendesk API User
    Author: hoebbel - 4/27/2011 12:48

    Hello Mr. Schubert,

    René Schubert schrieb:

    I have the following problem: I want to render
    - the complete navigation tree (expansionVisibility=all),

    - but only for the selected 1st level node and

    - no matter which sub-nodes of that 1st level node are selected (wholePathSelected=1)

    I would do it using two navigation functions.

    The first function is to dynamically define the start folder:

    <CMS_FUNCTION name="Navigation" resultname="fr_pt_getrootfolder">

    <CMS_PARAM name="expansionVisibility" value="purepath"/>

    <CMS_PARAM name="wholePathSelected" value="1"/>

    <CMS_ARRAY_PARAM name="selectedHTML">

    <CMS_ARRAY_ELEMENT index="0">$CMS_VALUE(#nav.folder.referenceName)$</CMS_ARRAY_ELEMENT>

    </CMS_ARRAY_PARAM>

    </CMS_FUNCTION>

    The second one is for the output itself:

    <CMS_FUNCTION name="Navigation" resultname="fr_sc_navigation">

    <CMS_VALUE_PARAM name="root" value="fr_pt_getrootfolder.toString()"/>

    <CMS_PARAM name="expansionVisibility" value="all"/>

    <CMS_PARAM name="wholePathSelected" value="1"/>

    <CMS_ARRAY_PARAM name="selectedHTML">

    <CMS_ARRAY_ELEMENT><![CDATA[-"$CMS_VALUE(#nav.id + " " + #nav.label)$"-<br>]]></CMS_ARRAY_ELEMENT>

    </CMS_ARRAY_PARAM>

    <CMS_ARRAY_PARAM name="unselectedHTML">

    <CMS_ARRAY_ELEMENT><![CDATA["$CMS_VALUE(#nav.id + " " + #nav.label)$"<br>]]></CMS_ARRAY_ELEMENT>

    </CMS_ARRAY_PARAM>

    </CMS_FUNCTION>

    But you may get problems, if you use startfolders or if you hide menu entries from the navigation.

    Best regards,

      Holger Höbbel

    0
  • Zendesk API User
    Author: baginski - 8/3/2012 14:43

    Hi,

    I have one issue with this solution. If a page is not referenced in the Sitestore, it causes a preview error (because the first function returns an empty String:

    (header function 'Navigation', resultname = 'fr_detailed_navigation' at 18, 2):  at 18, 2: invalid value for parameter 'root', invalid reference '')

    Interesting: even if the function is not called the function (remove the CMS_VALUE(fr_detailed_navigation) from the template) the error still remains - so I could not do any workarounds wih if-statements to repress the error message..

    Any Ideas ?

    Greetings,

    Michael

    0
  • Zendesk API User
    Author: hoebbel - 8/3/2012 15:01

    Hello Michael,

    if a page is not referred within the sitestore, you cannot determine the first level folder, since there is none.

    That the error remains, even if the function is not called, is probably due to a "preexecution" of the function [it is executed before the content is created]

    A possible Workaround (not tested) could be this:

    <CMS_VALUE_PARAM name='root' value='if(fr_pt_getrootfolder.isSet,fr_pt_getrootfolder.toString(),"pagefolder:root"'/>

    You can use any pagefolder name (root = sitestore root)

    Attention: You have to use two types of ticks here (' and ")

    If you just want to avoid the error, try to transfer the two function (and their output) to a format template and check, if the page is referred within the sitestore before calling the formattemplate.

    Disadvantage: You have to put the whole output within this format template, since it has a lower generation context, so that the there defined variables are not available within the page/section template

    Best regards,

      Holger

    0
  • Zendesk API User
    Author: baginski - 8/3/2012 15:37

    Hi Holger,

    thanks!

    the first way did not work properly (error was gone, but nothing has been rendered) -  the second possibily works fine for me! :smileycool:

    Greetings,

    Michael

    0

Please sign in to leave a comment.