Copied to clipboard

Flag this post as spam?

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


  • Johan Möller 83 posts 137 karma points
    Mar 05, 2010 @ 09:09
    Johan Möller
    0

    Why cant i do a if check around creating a variabel to see if there is any data.

      <xsl:if test="string($currentPage/data[@alias='prodImg1'])!=''" >

        <xsl:variable name="prodImg1" select="umbraco.library:GetMedia($currentPage/data [@alias='prodImg1'], 'false')/data [@alias = 'umbracoFile']" />

      </xsl:if>

     

    Why doesnt something like this work? theres nothing wrong with the way the variabel is created neither is there something wrong with the IF but if i put the if around the variabel to check if theres any data i get a error.

     

  • Tommy Poulsen 514 posts 708 karma points
    Mar 05, 2010 @ 09:33
    Tommy Poulsen
    2

    Hi Johan,

    you little code snippet is perfectly valid - but node the scope of the variable. Your "prodImg1" variable is only visible inside the if-element, and thus cannot be referenced outside the <xsl:if>...</xsl:if>.

    >Tommy

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Mar 05, 2010 @ 09:42
    Dirk De Grave
    0

    Hi Johan,

    Why would you create this variable if you're after the filename only? Can't you just use it as is, without declaring the variable first?

    (it's not an answer to your question tho...)

     

    Cheers,

    /Dirk

  • Johan Möller 83 posts 137 karma points
    Mar 05, 2010 @ 09:52
    Johan Möller
    0

    Ah ofc Tommy thx.

    Well the reason for decaring the variable is that im going to use this filepath in a couple of places and do the same thing with about 4 more files. So having a variable instead woud make my code more readable. But i guess im just gonna have to get media on all the places then.

    Shoudnt it be possible to give a variable null in value if the alias has no data? so i can create these and then check if the variable is null or not and create it then?

     

     

  • Tommy Poulsen 514 posts 708 karma points
    Mar 05, 2010 @ 09:56
    Tommy Poulsen
    1

    You ncan nest the if inside you variable, something like this:

        <xsl:variable name="prodImg1">
          <xsl:choose>
            <xsl:when test="string($currentPage/data[@alias='prodImg1'])!=''">
               <xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias='prodImg1'], 'false')/data [@alias = 'umbracoFile']" />
            </xsl:when>
            <xsl:otherwise>
              ...
            </xsl:otherwise>
          <xsl:choose>
        </xsl:variable>

    >Tommy

     

  • Johan Möller 83 posts 137 karma points
    Mar 05, 2010 @ 10:07
    Johan Möller
    0

    Oh, works great. Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft