简体   繁体   English

如何仅在Umbraco CMS的某些页面上显示一块模板?

[英]How do you only display a piece of a template on certain pages in Umbraco CMS?

I have a site built with Umbraco that has a sidebar with several widgets setup. 我有一个用Umbraco构建的网站,该网站的边栏包含几个小部件设置。 I need to set it so that one of the widgets (done as XSLT) will only display on a certain page. 我需要对其进行设置,以使其中一个小部件(作为XSLT完成)仅显示在特定页面上。 I've looked at using xsl:if test and matches and can't figure it out. 我看过使用xsl:if测试并匹配,但无法弄清楚。

You're on the right track, but get into the habit of including what you have tried already in your question (code etc). 您处在正确的轨道上,但是养成了在问题(代码等)中包含已经尝试过的内容的习惯。

The Quick + Dirty Method 快速+肮脏的方法

Find out the ID of you page (found on the properties tab of your node in the Content section) and use the following code: 找出您的页面ID(在“内容”部分的节点的属性选项卡上找到),然后使用以下代码:

<xsl:if test="$currentPage/@id = 1234">
    <!-- your widget here -->
</xsl:if>

The Cleaner Method 清洁方法

Always try to build your code to be scalable, for instance you may find that you want to include the widget on another page in the future, or deploying your content from staging to production might involve the node IDs changing without you realizing (not often, but can happen). 始终尝试构建可扩展的代码,例如,您可能会发现将来希望将小部件包含在另一个页面上,或者从暂存到生产的阶段部署内容可能会涉及到节点ID的更改,而您却没有意识到(通常,但有可能发生)。

Add a property to the page in question (let's call it showMyFancyWidget ) as true/false data type, flick it on in the Content section then use the following code: 将一个属性以true / false数据类型添加到有问题的页面(我们将其showMyFancyWidget ),在“内容”部分中轻拂该属性,然后使用以下代码:

<xsl:if test="$currentPage/showMyFancyWidget = 1">
    <!-- your widget here -->
</xsl:if>

This code will work for Umbraco v4.5.1 onwards. 此代码将适用于Umbraco v4.5.1及更高版本。 Not too sure about v5, but that's being discontinued in favor of v4.7 anyway 对v5不太确定,但是无论如何都不再支持v4.7

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

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