简体   繁体   中英

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. I need to set it so that one of the widgets (done as XSLT) will only display on a certain page. I've looked at using xsl:if test and matches and can't figure it out.

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:

<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).

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:

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

This code will work for Umbraco v4.5.1 onwards. Not too sure about v5, but that's being discontinued in favor of v4.7 anyway

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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