00schmidt
I'm new here

How to centralize a navigation function to be used by multiple page templates

Jump to solution

In an existing project there are various page templates with the same navigation function.

<CMS_HEADER>

...

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

   ...

    </CMS_FUNCTION>

...

</CMS_HEADER>

...

                $CMS_VALUEpage_nav)$

...

What is to be done to centralize the navigation function to avoid redundant code and to access it by the templates with an adequate call?

1 Solution

Accepted Solutions

Instead of calling the $CMS_VALUE()$ inside the format template, add the attribute 'context="PAGE"' to your header function and add the corresponding $CMS_RENDER()$ statement to the output channel of your page template (as early as possible, ideally directly after the header declaration). The results of the header function are then set to your page context and can be individually called just as if the functions were defined in the header of the page template itself.

You can add several functions to one format template this way.

View solution in original post

0 Kudos
4 Replies
C_Klingbeil
I'm new here

Hello Mr. Schmidt,

you can use a format template (Formatvorlagen) like "myNavigation" and put inside your code:


<CMS_HEADER>

...

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

   ...

    </CMS_FUNCTION>

...

</CMS_HEADER>

$CMS_VALUEpage_nav)$

In your page templates (Seitenvorlagen) you call this format template like that:

     $CMS_RENDER(template:"myNavigation")$

Hope, it'll help.

C. Klingbeil

Hey C. Klingbeil,

thanks for the reply. The solution above works fine. But I'd rather have preferred a solution where I can combine multiple function declarations, e.g. for a main navigation, a secondary navigation and something else within one single template object.to be included by each page. As far as I understand it, this would not be possible with the approach above as the $CMS_RENDER requires the $CMS_VALUE(...)$ within the rendered template object to do something useful.

Regards

Michael

0 Kudos

Instead of calling the $CMS_VALUE()$ inside the format template, add the attribute 'context="PAGE"' to your header function and add the corresponding $CMS_RENDER()$ statement to the output channel of your page template (as early as possible, ideally directly after the header declaration). The results of the header function are then set to your page context and can be individually called just as if the functions were defined in the header of the page template itself.

You can add several functions to one format template this way.

0 Kudos

Dear Andreas,

that's what I looked for. Thank you.

regards

Michael

0 Kudos