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
    Nov 12, 2010 @ 07:13
    syn-rg
    0

    Hide Div in Macro if no content is added

    Hi all,

    I'm trying to create a Testimonial macro. Where the user enters a "testimonial" a "testimonial name" and "testimonial details".

    I've inserted the macro in the template as I want the user to have the option of adding a testimonial to any page, however if no information is typed into the fields then the macro including the DIV do not display.

    I've added a true/false option on the following alias  - displayTestimonial

    Which isn't a bad option as they might enter a Testimonial onto that page, but later want to hide that testimonial.

    Here's the XSLT I've been working on so far:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    exclude-result-prefixes="msxml
    umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes
    Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings
    Exslt.ExsltSets "
    >


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>


    <xsl:template match="/">

    <!-- start writing XSLT -->
      <xsl:choose>
        <xsl:when test="string($currentPage/data[@alias='displayTestimonial']) = '1'">
          <div id="testimonial">
            <span>Testimonial</span>
            <xsl:if test="$currentPage/testimonial != ''">
              <h1><xsl:value-of select="$currentPage/testimonial" /></h1>
            </xsl:if>      
            <xsl:if test="$currentPage/testimonialName != ''">
              <h2><xsl:value-of select="$currentPage/testimonialName" /></h2>
            </xsl:if>      
            <xsl:if test="$currentPage/testimonialDetails != ''">
              <p><xsl:value-of select="$currentPage/testimonialDetails" /></p>
            </xsl:if>
          </div>
        </xsl:when>
      </xsl:choose>
    </xsl:template>

      
    </xsl:stylesheet>
  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 12, 2010 @ 08:11
    Dirk De Grave
    1

    Seems you're mixing two different xml schema's. Your test uses the old schema whereas you display data using the new xml schema. So either change your test to

    <xsl:when test="string($currentPage/displayTestimonial) = '1'">

    and output the content using the statements in your snippet or keep your test statement and use

    <div id="testimonial">
            <span>Testimonial</span>
            <xsl:if test="$currentPage/testimonial != ''">
              <h1><xsl:value-of select="$currentPage/data [@alias = 'testimonial']" /></h1>
            </xsl:if>      
            <xsl:if test="$currentPage/testimonialName != ''">
              <h2><xsl:value-of select="$currentPage/data [@alias = 'testimonialName']" /></h2> </xsl:if>       <xsl:if test="$currentPage/testimonialDetails != ''"> <p><xsl:value-of select="$currentPage/data [@alias = 'testimonialDetails']" /></p> </xsl:if> </div>

    So, depending on your settings for 

    <UseLegacyXmlSchema>true|false</UseLegacyXmlSchema>

    use the first (true) or second code (false) snippet

     

    Hope this helps.

    Regards,

    /Dirk

  • syn-rg 282 posts 425 karma points
    Nov 14, 2010 @ 23:31
    syn-rg
    0

    Thanks Dirk,

    I used the first option and it's now working, thanks for your help!

    Cheers,

    JV

Please Sign in or register to post replies

Write your reply to:

Draft