简体   繁体   English

N2共同内容

[英]N2 common content

The N2 documentation on inheritance mentioned about putting common content into the start page definition then within the masterpage retrieving that part of the content from the StartPage rather than the CurrentPage. 关于继承的N2文档提到了将通用内容放入起始页定义,然后在母版页中从StartPage而不是CurrentPage检索那部分内容的问题。 Is this considered to be best practice or is there another way to inherit content from the ancestor pages? 这被认为是最佳实践,还是有另一种方法可以从祖先页面继承内容?

There are three aspects to this 这有三个方面

  1. If you have some content that appears on more than one page, eg company contact phone that appears on site footer on every page, best practice would be to add this as a property to start page, probably on a separate tab (eg "Footer"), populate its value, and then reuse property value on all pages by reading from start page. 如果您有一些内容显示在多个页面上,例如,每个页面的站点页脚上都显示了公司联系电话,则最佳做法是将其添加为开始页面的属性,可能在单独的标签上(例如“页脚” ),填充其值,然后通过从起始页读取在所有页面上重用属性值。 Benefit of this is centralized editing of such reused property 这样做的好处是可以对此类重用属性进行集中编辑

  2. If you have some property that is the same on groups of pages - like when you have "theme color" same for all children of certain 1st level menu item - then you can use same approach on the level of children of start page - you would define property on child of start page (eg color), then reuse it on all of its children. 如果您具有在页面组上相同的某些属性(例如,对于某些第一级菜单项的所有子级都具有相同的“主题颜色”,那么您可以在起始页面的子级上使用相同的方法)在起始页的子项上定义属性(例如颜色),然后在其所有子项上重用它。 Once editor sets "theme color" on 1st level page, it will automatically affects all its children. 编辑器在第一级页面上设置“主题颜色”后,将自动影响其所有子级。

  3. If you have property with some kind of user-defined default value but you want editor to be able to override it, like header image, you would use combined approach. 如果您的属性具有某种用户定义的默认值,但希望编辑器能够覆盖它,例如标题图像,则可以使用组合方法。 Define HeaderImage property on start page and on all other pages. 在开始页面和所有其他页面上定义HeaderImage属性。 Then, in your code, if HeaderImage property is empty, use one from start page. 然后,在您的代码中,如果HeaderImage属性为空,请从起始页使用一个。 This is a good practice since people tend to make mistakes and forget things. 这是一个好习惯,因为人们往往会犯错误并忘记事情。 In this case, if Header image is not specified, it will be automatically replaced by value from StartPage 在这种情况下,如果未指定页眉图片,则会自动将其替换为StartPage中的值

All three scenarios are used in real life conditions and proved over and over again to be good solutions. 所有这三种方案都在现实生活中使用,并一再证明是很好的解决方案。

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

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