Copied to clipboard

Flag this post as spam?

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


  • Dwayne A 97 posts 117 karma points
    Feb 16, 2011 @ 17:55
    Dwayne A
    0

    Problem: Media Picker xslt in 4.6.1

    Hi,

    I've created simple media pickers before using the umbraco library, but can't get it to fly in 4.6.1.

    When using select of, it wont accept the old syntax $currentPage/data [@alias = "mediaItem"], but suggests   <xsl:value-of select="$currentPage/pageImage"/>. This produces an ID in visualizer, no problem.

    It arises when creating: <xsl:value-of select="umbraco.library:GetMedia($currentPage/pageImage, 'false')"/>. Neither the older syntax or this I have tried works without an error on saving: System.OverflowException: Value was either too large or too small for an Int32.

    Can anyone help out?

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Feb 16, 2011 @ 18:28
    Bo Damgaard Mortensen
    0

    Hi Dwayne,

    Sound weird - are you using the GetMedia() inside a loop? :-)

    I just checked my xslt for my latest where I'm doing the exact same using the new scheme, my code looks like this:

    <xsl:for-each select="$currentPage/ancestor-or-self::*/*/Reklame [@isDoc]">
        <xsl:variable name="media" select="umbraco.library:GetMedia(current()/billede, 0)" />

    Can I maybe trick you into pasting some more of your code? 

    Thanks!

    / Bo

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Feb 16, 2011 @ 18:57
    Bo Damgaard Mortensen
    0

    Just noticed that you're using: 

    <xsl:value-of select="umbraco.library:GetMedia($currentPage/pageImage, 'false')"/>

    Try it like this:

    <xsl:variable name="image" select="umbraco.library:GetMedia($currentPage/pageImage, 0)" />
    <img>
            <xsl:attribute name="src">
                    <xsl:value-of select="$image/umbracoFile" />
            </xsl:attribute>

    </img>  

    See if that works :-)


  • Rob Watkins 369 posts 701 karma points
    Feb 16, 2011 @ 19:12
    Rob Watkins
    0

    If you are getting this error on saving it may be because there is no $currentPage when you save, which always throws an exception calling the library functions.

    If it is this, you can either uncheck the validation on save and it will work when it is embedded on content; or because I like everything to work everywhere, what I normally do is create an xsl:variable for the media ID and use an xsl:choose element to set it to 1 when there is no current page.

  • Dwayne A 97 posts 117 karma points
    Feb 16, 2011 @ 19:32
    Dwayne A
    0

    Thanks for the speedy replies! For starters, I have everything in place: page, property (pageImage) macro, xslt. Oddly, enough, I can save it with another property name, but get an error with pageItem, and I am certain spelling/casing is correct.

    @Bo: Sure thing. See what you can make of it.

    <xsl:param name="currentPage"/>
    <xsl:template match="/">
      <xsl:value-of select="$currentPage/pageImage"/>
      <xsl:value-of select="umbraco.library:GetMedia($currentPage/pageImage, 'false')/data [@alias = 'umbracoFile']" />
      <img src="{umbraco.library:GetMedia($currentPage/pageImage, 'false')/data [@alias = 'umbracofile']}" />
    </xsl:template>

    @Rob: I have a page. The macro is in place in a template.

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Feb 16, 2011 @ 20:29
    Bo Damgaard Mortensen
    0

    Dwayne,

    Try this and see if it works for you :-)

    <xsl:variable name="image" select="umbraco.library:GetMedia($currentPage/pageImage, 0)" />
    <img>
            <xsl:attribute name="src">
                    <xsl:value-of select="$image/umbracoFile" />
            </xsl:attribute>

     

    </img>  

    / Bo

  • Dwayne A 97 posts 117 karma points
    Feb 16, 2011 @ 20:34
    Dwayne A
    0

    Hej Bo,

    I have tried that, but get an error (System.OverflowException: Værdien var enten for stor eller for lille til en Int32) unless I check "Skip testing (ignore errors)". It does work if I turn errors off, but I'm still puzzled.

  • Dwayne A 97 posts 117 karma points
    Feb 16, 2011 @ 20:46
    Dwayne A
    0

    Bo, I got it to work fine on another xslt page, running on a different macro/template. I'm suspecting something is amiss with the structure of my template or...? Hmmm.

    Also, I got this to work as well.

    <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/pageBillede, false)" />
      <img src="{$media/umbracoFile}" alt="{$media/altText}" />

    Now I have a new issue when a child page on the template does not require an image, The browser returns a parsing error. Any tips on creating a test?

     

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Feb 17, 2011 @ 00:35
    Bo Damgaard Mortensen
    0

    Hi again Dwayne,

    It sure sounds weird that it works on another template, what exactly would be the difference from one template to another? :-)

    I think you could make a test to see if the mediapicker holds an media item, something like this:

    <xsl:if test="$media != ''">
    
    </xsl:if>

    .. or:

    <xsl:if test="$media != null">
    
    </xsl:if>

    I can't remember exactly which of these it is ;-)

    Let me know if it works for you!

    Thanks,

     

    Bo

  • Rob Watkins 369 posts 701 karma points
    Feb 17, 2011 @ 11:11
    Rob Watkins
    0

    The above might not work; you can't pass empty strings into the library functions, so you need to check the media ID before you pass it in. You could then check the media item afterwards in case the ID has since been deleted for completeness. This will also deal with no current page on save because the mediaID will be blank in that case too:

    <xsl:variable name="mediaID" select="$currentPage/pageBillede" />
    <xsl:if test="string($mediaID) != ''">
    <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/pageBillede, false)" />
    <xsl:if test="string($media) != ''">
    <img src="{$media/umbracoFile}" alt="{$media/altText}" />
    </xsl:if>
    </xsl:if>

  • Dwayne A 97 posts 117 karma points
    Feb 17, 2011 @ 13:32
    Dwayne A
    0

    @Rob: That was the test I was looking for. Have not tried it yet, but I will check it out asap. This should also prevent the browser from returning an error if certain pages do not inject an image in the propert/media picker, I would assume?

  • Rob Watkins 369 posts 701 karma points
    Feb 17, 2011 @ 14:12
    Rob Watkins
    0

    It should do, give it a whirl - it was straight from brain to forum, so it may not work, but I've just had a look at what I'm using in an ImageGen portfolio doobrie I wrote and it looks basically the same.

  • Dwayne A 97 posts 117 karma points
    Feb 24, 2011 @ 18:58
    Dwayne A
    0

    Thanks Rob. That did the trick it seems. Sorry it took a while to get back. Swamped ;-)

    What's the best way to set parameters on media picker? Here I'm thinking particulary of alt tags a user can set when chosing an image..

  • Rob Watkins 369 posts 701 karma points
    Feb 25, 2011 @ 11:33
    Rob Watkins
    0

    I'm not sure I understand your question - do you mean dealing with both cases when there are alt tags, and when there aren't?

    If so, I would do this:

    <img src="{$media/umbracoFile}">
    <xsl:if test="$media/altText != ''">
    <xsl:attribute name="alt"><xsl:value-of select="$media/altText"/></xsl:attribute>
    </xsl:if>
    </img> 

    Repeat for title and any other attributes that may or may not be present. 

    That will result in neater markup if the attributes are not present.

    One caveat with that is that I'm pretty sure that alt is a required attribute on the XHTML doctypes at least, so if W3C validation is important to you you may in fact want to force that to the filename or something if it is not present (if umbraco does not already do that).

  • Dwayne A 97 posts 117 karma points
    Feb 25, 2011 @ 13:21
    Dwayne A
    0

    Yeah, sorry, I guess my question was not clear. I mean, how can alt tags be written at all with the media picker, or in the tinyMCE editor, for that matter? There are no fields. I would like to include these. Any ideas how to add them? This is another topic altogether. Just thought you might know.

  • Rob Watkins 369 posts 701 karma points
    Feb 25, 2011 @ 14:09
    Rob Watkins
    0

    Aha, no, sorry, not something I've ever done I'm afraid! I do vaguely recall looking at the media picker and wondering why it didn't allow you to allow alt tags though; I never followed it up though.

  • Dwayne A 97 posts 117 karma points
    Feb 25, 2011 @ 15:08
    Dwayne A
    0

    Yeah, I find it bizarre it's not a defacto parameter, among others. I'll have to dig elsewhere. Thanks again Rob for the help with the xsl.

Please Sign in or register to post replies

Write your reply to:

Draft