Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • syn-rg 282 posts 425 karma points
    May 03, 2012 @ 09:54
    syn-rg
    0

    Hide div when parent is certain doc type

    Hi all,

    I'm trying to hide or show div items depending on what the current doc type is or what it's ancestor doc type is.

    However if I try to use "ancestor-or-self" the div will display, on the current page and it's child nodes. It only works on the current page when I use "self". But it still displays on the child nodes.

    Any ideas as to what will fix this?

    Cheers, JV

    Here's my XSLT:

     

  • syn-rg 282 posts 425 karma points
    May 03, 2012 @ 09:55
    syn-rg
    0
        <!-- HIDES FROM HOME PAGE -->
        <xsl:choose>
          <xsl:when test="$currentPage/self::*[@isDoc and string(umbracoNaviHide) != '1' and name() != 'umbHomepage']">
            <!-- HIDES FROM ELECTRICAL PAGES -->
            <xsl:choose>
              <xsl:when test="$currentPage/self::*[@isDoc and string(umbracoNaviHide) != '1' and name() != 'YourElectricityPage']">
                <div class="faults_emergencies">
                  <h1>132 099</h1>
                  <p>Electrical faults &amp; emergencies</p>
                </div>
              </xsl:when>
              <xsl:otherwise></xsl:otherwise>
            </xsl:choose>
            <!-- HIDES FROM ELECTRICAL PAGES -->
            <xsl:choose>
              <xsl:when test="$currentPage/self::*[@isDoc and string(umbracoNaviHide) != '1' and name() != 'YourGasPage']">
                <div class="faults_emergencies">
                  <h1>132 691</h1>
                  <p>Gas faults &amp; emergencies</p>
                </div>
              </xsl:when>
              <xsl:otherwise></xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:otherwise></xsl:otherwise>
        </xsl:choose>
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 03, 2012 @ 10:06
    Chriztian Steinmeier
    0

    Hi JV,

    You should really use the apply-templates approach for something like this - here's the basic gist of how it works:

    <xsl:template match="/">
    <!-- Run the template for the current page's alias -->
        <xsl:apply-templates select="$currentPage" />
    </xsl:template>
    
    <!-- Custom templates -->
    <xsl:template match="YourElectricityPage">
        <div>
            I am the Electricity Page
        </div>
    </xsl:template>
    
    <xsl:template match="YourGasPage">
        <div>
            I am the Gas Page
        </div>
    </xsl:template>

     

    This way you won't have to bend your head in a multitude of ways whenever a new page type needs to be added - you just add a new template - boom!

    If you have stuff that should be output for all pages - put it in the root template (match="/"). If you need to suppress a lot of other page types (aliases) you can add a generic template to suppress everything that doesn't have its own template, e.g.:

    <xsl:template match="*[@isDoc]" priority="-1">
    <!-- No content here - no output for these -->
    </xsl:template>

    /Chriztian 

Please Sign in or register to post replies

Write your reply to:

Draft