Copied to clipboard

Flag this post as spam?

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


  • Kasper Dyrvig 246 posts 379 karma points
    Oct 10, 2010 @ 18:13
    Kasper Dyrvig
    0

    Macro doesn't pass values?

    Why won't my macro "Videoplayer" pass the values video, picture and title to the xslt?

    My code is:

    <xsl:param
     name="v" select="/marco/Video"/>
    <xsl:param name="p" select="/macro/Picture"/>
    <xsl:param name="t" select="/macro/Title"/>

    <xsl:template match="/">
      <xsl:if test="$v != ''">
        <a class="videoplayer" id="player">
          <xsl:attribute name="href">
            <xsl:value-of select="umbraco.library:GetMedia($v, 0)/umbracoFile"/>>
          </xsl:attribute>
          <xsl:if test="$p != ''">
            <img alt="">
              <xsl:attribute name="src">
                <xsl:value-of select="umbraco.library:GetMedia($p, 0)/umbracoFile"/>
              </xsl:attribute>
              <xsl:attribute name="alt">
                <xsl:value-of select="$t"/>
              </xsl:attribute>
            </img>
          </xsl:if>
        </a>
      </xsl:if>

    </xsl:template>

    Your help is highly appreciated!

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 10, 2010 @ 19:55
    Dirk De Grave
    0

    try this:

    <xsl:variable name="v" select="/marco/Video"/>
    <xsl:variable name="p" select="/macro/Picture"/>
    <xsl:variable name="t" select="/macro/Title"/>

    <xsl:template
     
    match="/">
      <xsl:if test="$v != ''">
        <a class="videoplayer"
     
    id="player">
          <xsl:attribute name="href">
         
     
    <xsl:value-of select="umbraco.library:GetMedia($v,
     0)/umbracoFile"
    />>
          </xsl:attribute>
          <xsl:if test="$p != ''">
            <img alt="">
           
       
    <xsl:attribute name="src">
           
         
    <xsl:value-of select="umbraco.library:GetMedia($p,
     0)/umbracoFile"
    />
              </xsl:attribute>
              <xsl:attribute name="alt">
           
         
    <xsl:value-of select="$t"/>
           
       
    </xsl:attribute>
            </img>
          </xsl:if>
        </a>
      </xsl:if>

    </xsl:template>

    Also check the aliases of the parameters you're passing, these are case sensitive.

     

    Cheers,

    /Dirk

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 11, 2010 @ 09:42
    Chriztian Steinmeier
    0

    Hi Webspas,

    You've misspelled "macro" as "marco" in the very first line (D'oh! :-)

    Since the rest of the code relies on this first $v parameter, nothing is output...

    /Chriztian

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 11, 2010 @ 09:45
    Dirk De Grave
    0

    Hehe, forgot to change that, I was aware of that misspelling, just forgot to change it in my code snippet, thanks for rectifying it Chriztian!

     

    @Chriztian, does that mean you're also allowed to use <xsl:param> instead of <xsl:variable>?

     

    Cheers,

    /Dirk

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 11, 2010 @ 09:52
    Chriztian Steinmeier
    0

    Yes and no - parameters are the only kind you can set from the outside (whether that's from outside of a template with the <xsl:with-param> instruction, or the way $currentPage gets set from the XSLT processor).

    /Chriztian 

     

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 11, 2010 @ 15:48
    Kasper Dyrvig
    0

    A great thanks for your replies!

    But I still don't get any output at all...?!

    The code now looks like this:

    <xsl:param name="v" select="/macro/Video"/>
    <xsl:param name="p" select="/macro/Picture"/>
    <xsl:param name="t" select="/macro/Title"/>

    <xsl:template match="/">
    <xsl:if test="$v != ''">
      <a class="videoplayer" id="player">
        <xsl:attribute name="href">
          <xsl:value-of select="umbraco.library:GetMedia($v, 0)/umbracoFile"/>
        </xsl:attribute>
        <xsl:if test="$p != ''">
          <img>
            <xsl:attribute name="src">
              <xsl:value-of select="umbraco.library:GetMedia($p, 0)/umbracoFile"/>
            </xsl:attribute>
            <xsl:attribute name="alt">
              <xsl:value-of select="$t"/>
            </xsl:attribute>
          </img>
        </xsl:if>
      </a>
    </xsl:if>

    </xsl:template>
  • Ernst Utvik 123 posts 235 karma points
    Oct 11, 2010 @ 15:57
    Ernst Utvik
    0

    I use a variable like this on my xslt's

    <xsl:variable name="OutputLimit" select="/macro/outLimit"/>


    Did you add the parameter? Fint the macro for the xslt under the "macros" section and add your parameters under the parameters tab.

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 11, 2010 @ 18:34
    Kasper Dyrvig
    0

    Yes I did add the parameters (see the screenshot below)

    And in the ritch text editor the macro looks like this:

    <div umb_video="1077" umb_macroalias="Videoplayer" umb_picture="1060" umb_title="Guldmedia showreel" ismacro="true" onresizestart="return false;" umbversionid="c99f3ca3-1220-460c-ab2d-d87c17faac76" umbpageid="1050" title="This is rendered content from macro" class="umbMacroHolder"><!-- startUmbMacro --><span>This macro does not provides rendering in WYSIWYG editor</span><!-- endUmbMacro --></div>
  • Johan Roug 97 posts 153 karma points
    Oct 11, 2010 @ 20:55
    Johan Roug
    0

    try writing some lorem ipsum before the if statement. Do you get anything out at all?

    If not, did you remember to put your field on your template?

    <umbraco:Item field="yourmacroname" runat="server">umbraco:Item>

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 12, 2010 @ 08:29
    Kasper Dyrvig
    0

    Yes, I do get output if I type something befor and/or after the if statement.

    Could it be something with the parameter names or alias? Or types?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 12, 2010 @ 10:44
    Chriztian Steinmeier
    0

    Hi Webspas,

    Are you getting no output at all, or is it just the src attributes that are empty? Seems weird that you're getting no output at this point... which version of Umbraco are you using?

    Tried dumping the raw XML (macro & mediaNodes)? e.g.:

    <textarea><xsl:copy-of select="/"></textarea>
    <textarea><xsl:copy-of select="umbraco.library:GetMedia(/macro/Video, 0)" /></textarea>
    <textarea><xsl:copy-of select="umbraco.library:GetMedia(/macro/Picture, 0)" /></textarea>
    

    /Chriztian 

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 12, 2010 @ 18:01
    Kasper Dyrvig
    0

    Okay now we are getting somewhere.

    Now I get this output:

    <a class="videoplayer" id="player" href="/media/520/videofile.flv1040503"><img src="/media/99/videoimage.jpg28925137674" alt="Showreel"></a>

    From this XSLT-code:

    <xsl:variable name="video" select="/macro/video"/>
    <xsl:variable name="picture" select="/macro/picture"/>
    <xsl:variable name="title" select="/macro/title"/>

    <xsl:template match="/">
    <xsl:if test="$video != ''">
      <a class="videoplayer" id="player">
        <xsl:attribute name="href">
          <xsl:value-of select="$video"/>
        </xsl:attribute>
        <xsl:if test="$picture != ''">
          <img>
            <xsl:attribute name="src">
              <xsl:value-of select="$picture"/>
            </xsl:attribute>
            <xsl:attribute name="alt">
              <xsl:value-of select="$title"/>
            </xsl:attribute>
          </img>
        </xsl:if>
      </a>
    </xsl:if>

    </xsl:template>

    But I'm not sure how to get onlt the path for the videofile and the videoimage...

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 12, 2010 @ 18:17
    Kasper Dyrvig
    0

    I now have some more information: The macro parameter type "mediaCurrent" stores more than just the ID for a media node. It stores every thing from the selected media.

    So does anyone have an idea to avoid that? An idea that goes further that manually type the ID for the media node...

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 12, 2010 @ 20:55
    Chriztian Steinmeier
    0

    Hi Webspas,

    Please forgive us - the entire community - for this :-)

    D'oh! - of course - I just couldn't make sense of it - until now, of course...

    Well, you just need to pick the parts you need - no need to call GetMedia(), since you've already got the mediaNode data - just make your way to the umbracoFile property of each:

    <xsl:variable name="video" select="/macro/video"/>
    <xsl:variable name="picture" select="/macro/picture"/>
    <xsl:variable name="title" select="/macro/title"/>
    
    <xsl:template match="/">
        <xsl:if test="$video != ''">
            <a class="videoplayer" id="player" href="{$video/umbracoFile}">
                <xsl:if test="$picture != ''">
                    <img src="{$picture/umbracoFile}" alt="{$title}" />
                </xsl:if>
            </a>
        </xsl:if>
    </xsl:template>
    
    Note, I'm using curly braces (called an "Attribute Value Template") instead of the verbose <xsl:attribute> element (much better when you can just pick the data needed).
    /Chriztian
  • Kasper Dyrvig 246 posts 379 karma points
    Oct 12, 2010 @ 22:24
    Kasper Dyrvig
    0

    Now I'm going to show you some funny stuff...

    I have already tried what you suggest, but for some reason that dosen't work for me (or Umbraco). I know that it is the typical way to do it with normal GetMedia calls, but this is strange!

    When I do it like you (Chriztian) posted, I get an empty link with an empty image. The alt attribute is correct.

    <a class="videoplayer" id="player" href=""><img src="" alt="Blabla"></a>

    When I remove the "umbracoFile" I get this:

    <video><Video id="1077" version="9c39a521-f66b-4bc2-9948-4f728e898f68" parentID="1074" level="2" writerID="0" nodeType="1076" template="0" sortOrder="1" createDate="2010-10-10T17:56:58" updateDate="2010-10-10T17:56:52" nodeName="flow" urlName="flow" writerName="Administrator" nodeTypeAlias="Video" path="-1,1074,1077"><umbracoFile>/media/520/videofile.flv</umbracoFile><umbracoVideoImage>/media/633/testervideoimage.jpg</umbracoVideoImage><umbracoBytes>22461</umbracoBytes></Video></video><a class="videoplayer" id="player" href=""><img src="" alt="Blabla"></a>

    Note I have created a new media type now that contains both the videofile and the image. But I have tried the same solution earlier with almost same result.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 12, 2010 @ 22:35
    Chriztian Steinmeier
    0

    Oh darn it - there's a bug from 4.5.1 I think that wasn't fixed for mediaCurrent items... do this (now based on your new type):

    <xsl:variable name="video" select="/macro/video"/>
    <xsl:variable name="title" select="/macro/title"/>
    
    <xsl:template match="/">
            <xsl:if test="$video != ''">
                    <a class="videoplayer" id="player" href="{$video/umbracoFile}">
                            <xsl:if test="$video//umbracoVideoImage != ''">
                                    <img src="{$video//umbracoVideoImage}" alt="{$title}" />
                            </xsl:if>
                    </a>
            </xsl:if>
    </xsl:template>
    
    

    Note the double slashes (//) to get to the properties...

    (Don't know if you're still using title in that way - but you know what to do with it...)

    /Chriztian

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 13, 2010 @ 08:11
    Kasper Dyrvig
    0

    Yeay! That was it!

    Thank you very much. And I'm sorry that I have forgot to repport what version I am using - it is 4.5.2 be the way.

Please Sign in or register to post replies

Write your reply to:

Draft