简体   繁体   English

如何将导航添加到自定义Magnolia CMS模板?

[英]How to add navigation to a custom Magnolia CMS template?

I've managed to create a custom page template for Magnolia CMS pretty easily following this tutorial: 我已经成功地按照本教程为Magnolia CMS创建了一个自定义页面模板:

http://documentation.magnolia-cms.com/templates/introduction.html http://documentation.magnolia-cms.com/templates/introduction.html

However, I'm at the point where I'd like to insert the navigation into my template but I can't find a simple way to do so. 但是,我正处于将导航插入模板的位置,但我找不到一种简单的方法。 It looks like other's have had this problem with no clear way to fix it. 看起来其他人有这个问题没有明确的方法来解决它。 Does anyone know how to easily include the navigation? 有谁知道如何轻松包含导航? Thanks 谢谢

If you're using Magnolia CE (Community Edition) 4.5.x, you need to know that basically every page template extends the one defined in /modules/standard-templating-kit/config/site/templates/prototype . 如果您使用的是Magnolia CE(Community Edition)4.5.x,您需要知道基本上每个页面模板都扩展了/modules/standard-templating-kit/config/site/templates/prototype There you have a node, /navigation . 你有一个节点/navigation You can copy that node to your new custom template, and after that you can start playing with it's properties. 您可以将该节点复制到新的自定义模板,然后您可以开始使用它的属性。

But before that, don't forget to include the navigation menu(s) somewhere in your main template file ( .ftl ) and make your template to use stk model class info.magnolia.module.templatingkit.templates.pages.STKPageModel (add an attribute to your template named modelClass, look at stkArticle (or stkSection), it's a good place to start) 但在此之前,不要忘记在主模板文件( .ftl )中的某处包含导航菜单,并使模板使用stk模型类info.magnolia.module.templatingkit.templates.pages.STKPageModel (add你的模板名为modelClass的属性,看看stkArticle(或stkSection),这是一个好的开始)

Horizontal navigation: 水平导航:

[#if def.navigation.top]
    [#include def.navigation.horizontal.template]
[/#if]

Vertical nav: 垂直导航:

[#if def.navigation.top]
    [#include def.navigation.vertical.template]
[/#if]

If you want to include your menu in another template included with a [@cms.area ...] tag, you can use this code: 如果要将菜单包含在[@cms.area ...]标记附带的另一个模板中,可以使用以下代码:

[#if model.root.def.navigation.top]
    [#include model.root.def.navigation.vertical.template]
[/#if]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM