简体   繁体   English

在SilverStripe中自定义导航菜单

[英]Customizing Navigation Menu in SilverStripe

I asked this question in SilverStripe forum, but haven't heard in a day. 我在SilverStripe论坛中提出了这个问题,但是一天没听到。 http://silverstripe.org/customising-the-cms/show/263604#post263604 http://silverstripe.org/customising-the-cms/show/263604#post263604

I am in the process of migrating a static PHP based site + Wordpress to SilverStripe. 我正在将基于PHP的静态站点+ Wordpress迁移到SilverStripe。

In the static pages, we customize the header itself. 在静态页面中,我们自定义标题本身。 We have two types of logins. 我们有两种类型的登录名。 Customers and Affiliates. 客户和会员。

In the static site today, we do something like this: 在今天的静态站点中,我们执行以下操作:

<? require("_header_top.html"); ?> 
<? if (isset($display_affiliate_link) && $display_affiliate_link == true) { 
require("_header_middle_affiliate.html"); 
} else { 
require("_header_middle.html"); 
} ?> 
<? require("_header_bottom.html"); ?> 

This is the only difference in the Navigation menu between the affiliate and customer sections. 这是会员和客户部分之间导航菜单中的唯一区别。

I tried going down the different layout path. 我尝试沿着不同的布局路径前进。 But I don't prefer it as the layouts look 99% the same except for this one. 但我不喜欢它,因为除此布局外,布局看起来保持99%相同。

I tried the following hack, which works, but I don't like it at all. 我尝试了以下技巧,但效果不错,但我一点都不喜欢。

<% if MenuTitle = Affiliate %> 
<a href="/affiliate_login>affiliate login</a> 
<% end_if %> 
<a href="/subscriber_login>subscriber login</a> 

Any suggestion on how I can achieve this more elegantly or a better recommended way to implement this? 关于如何更好地实现此目标或实现此目标的更好建议的任何建议?

Vikram 维克拉姆

I do not understand what is wrong with what you did... Other workarounds would be: 我不明白您的做法有什么问题。其他解决方法是:

  • Add a "Type" property for your SiteTree page object, in order to separate between a customer and an affiliate. 为您的SiteTree页面对象添加“类型”属性,以便在客户和会员之间进行区分。
  • Inside the SiteTree object's controller you can use the "customize" function which receives either an array or an object, and by calling the "renderWith" function which is also available inside the controller to render the array/object with a template file (.SS files). 在SiteTree对象的控制器内部,您可以使用“自定义”函数来接收数组或对象,并调用“ renderWith”函数,该函数也可以在控制器内部使用,以使用模板文件(.SS文件)。 This way your layout for a customer and an affiliate will be separated in different .SS files. 这样,您的客户和会员的布局将以不同的.SS文件分隔。

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

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