Copied to clipboard

Flag this post as spam?

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


  • FarmFreshCode 225 posts 422 karma points
    May 04, 2011 @ 18:21
    FarmFreshCode
    0

    Specific "If Statement" needed to display content only on Child Pages

    Hello Everyone,

    I believe I could use an "If Statement" to solve my issue below. Take a look at the image below to get an idea of my content tree.

    Inside of Template "A" I placed the following code:

    <h2>Contact Information</h2>
    <strong><umbraco:Item field="DeapartmentTitle" recursive='true' runat="server"></umbraco:Item></strong><br>
    <umbraco:Item field="DepartmentBuilding" recursive='true' runat="server"></umbraco:Item>, suite <umbraco:Item field="DeapartmentRoomNumber" recursive='true' runat="server"></umbraco:Item><br>
    Phone: <umbraco:Item field="DeapartmentPhone" recursive='true' runat="server"></umbraco:Item>

    You'll notice that there are some pieces of regular text like (Contact Informaiton, suite, Phone: ect.) included.
    But I don't want this section to show up at all on the Level 1 pages that use Template "A"

    What I would like to do is have a statement in Template “A” that says:
    If your Parent (or parent’s parent, ect.) is using template “B” then show
    this section of code. If there is no parent using the template “B” then show
    nothing.

    Is that possible? To wrap this section of code in an if statement?

    My Goal here is to allow my department's admin update his contact information on his main page (which uses Template "B") and then be able to show that information on all of his sub pages. I would also like not to create an additional template just to suit this need.

     

  • Jesper Hauge 298 posts 487 karma points c-trib
    May 04, 2011 @ 22:58
    Jesper Hauge
    0

    Hi FarmFreshCode,

    First of all: I'm pretty sure you're also using two different document types for the documents in in your tree, since that is the only possible way to have documents with different icons, these document types 

    I'd probably use a little xslt-file and a macro to solve this problem. But you could do it from a masterpage's codebehind as well if you needed to. Here's my take on a solution using a xslt macro (this code is assuming you're on a recent version of Umbraco using the new xml schema)

    <xsl:template match="/">
        <!-- 
        The code below will only output something if there's a page in the path 
        above the currentpage that is based on DoctypeB
        -->
        <xsl:apply-templates select="$currentPage/ancestor-or-self::DoctypeB" />
    </xsl:template>
    
    <xsl:template match="DoctypeB">
        <h2>Contact information</h2>
        <strong><xsl:value-of select="./DepartmentTitle" /></strong><br />
        <!-- More html/property values here -->
    </xsl:template>

    You'd need to create a xslt file for the above code, and a macro to render it and then insert the macro in your template using an <umbraco:Macro /> tag.

    Regards
    Jesper Hauge

  • FarmFreshCode 225 posts 422 karma points
    May 05, 2011 @ 14:08
    FarmFreshCode
    0

    Nice. Thanks Jesper! I put that example in place and it seems to be working out just great. Thats a much cleaner solution than "if statements".

Please Sign in or register to post replies

Write your reply to:

Draft