Copied to clipboard

Flag this post as spam?

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


  • Nathan McGuirk 7 posts 27 karma points
    Jul 08, 2013 @ 17:16
    Nathan McGuirk
    0

    How to test if an Umbraco property is used

    Hi All,

    I've been working on an issue, and it basically comes down to the behavior of pulling umbraco.library.

    In C# and in XSLT I'm doing simple checks to see if the user has entered a value into a property field. In XSLT, my code appears as such:

    <xsl:variable name="media" select="umbraco.library:GetMedia(sectionImage, 0)" />
    <xsl:if test="$media">
    <xsl:variable name="url" select="$media/umbracoFile" />
    <xsl:element name="img"><xsl:attribute name="src"><xsl:value-of select="$url" />
    </xsl:element>
    </xsl:if>

    Which works just fine if there's an actual image being selected and uploaded by the user.

    But if the property field is blank, then it will error out unable to parse the XSLT. This error came up last Friday in C#, and I spent this morning converting the behavior to an XSLT macro.

    When the error was in C#, the value I would get back on these umbraco.library calls for elements without content was "umbraco.presentation.nodeFactory.Property". This filler content tricked the if test, and would continue on through the remaining code.

    Can anyone help with a solution on how to test if a non-manditory property has content so I can style pages accordingly?

    Thank you all for your time,
    Nathan

Please Sign in or register to post replies

Write your reply to:

Draft