Copied to clipboard

Flag this post as spam?

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


  • MartinB 411 posts 512 karma points
    Sep 10, 2010 @ 15:59
    MartinB
    0

    GetMedia 1-line image reference in 4.5.1 ?

    Hi

    I made a template with an image alias (mediapicker), alt tag (textstring) and linktitle (textstring)

    In the old schema i used this on a clients webpage to reference childnode images (without setting variables):

    <img src="{umbraco.library:GetMedia(data [@alias = 'mainImage'],0)/data[@alias = 'umbracoFile']}" class="myClass" />  

    I'vre read numerous topics on the forum regarding 4.5 schema image reference with GetMedia, but i can't get it to work, even when setting a variable first. Any suggestions?

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Sep 10, 2010 @ 17:35
    Kim Andersen
    1

    Hi Martin

    How about this line of code:

    <img src="{umbraco.library:GetMedia(mainImage,0)/umbracoFile}" class="myClass" />  

    Does that work for you?

    /Kim A

  • bob baty-barr 1180 posts 1294 karma points MVP
    Sep 11, 2010 @ 04:14
    bob baty-barr
    0

    i think you may have to use /umbracoFile/Image -- but not 100% sure.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 11, 2010 @ 10:03
    Dirk De Grave
    0

    Guess it should be /Image/umbracoFile?

     

    Cheers,

    /Dirk

  • Hendrik Jan 71 posts 137 karma points
    Sep 11, 2010 @ 12:25
    Hendrik Jan
    0

     

    If i am not mistaking 4.5.1 has a bug with the GetMedia function, it gives back more than you expect

     

    Try this:

    <img src="{umbraco.library:GetMedia(mainImage,0)/Image/umbracoFile}" class="myClass" /> 

     

    Or if that doesnt work

     

    <img src="{umbraco.library:GetMedia(mainImage,0)/Folder/Image/umbracoFile}" class="myClass" />  

     

  • MartinB 411 posts 512 karma points
    Sep 11, 2010 @ 13:31
    MartinB
    0

    Thanks for all your kind replies and help

    Kim had the solution to this problem. But why?

    I'm a bit confused about how there can be so many different suggestion to the same "little" problem. Is there somewhere i can pick up a book or another type of reference, that'll teach me correct xslt for the new schema?

    Again thanks a bunch for all your help and inputs!

  • Kim Andersen 1447 posts 2196 karma points MVP
    Sep 11, 2010 @ 13:58
    Kim Andersen
    1

    Hi Martin

    I think the reason why there can be some confusion about the GetMedia-extension and path to the images is because of a bug in v4.5 where you needed to reference the root element of the media-element as well. If you take a look a Dirks answer and the first snippet that Niels provided you'll see that they both suggested an extra /Image to the path. Theese solutions will work if you had used v4.5, because of the bug.

    But the bug has been fixed i v4.5.1 so that's why we don't need to use the extra /Image in the expression.

    A good idea is to check how the XML looks by writing it out in a textarea. Like this:

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

    You can do the same with $currentPage to see the XML on the current page, variables etc.. I think it's a good way of checking if we are writing the right XSLT. Does that make sense at all? :D

    Anyway, I'm glad it worked out for you  :)

    /Kim A

  • MartinB 411 posts 512 karma points
    Sep 11, 2010 @ 17:02
    MartinB
    0

    Hi Kim

    Don't worry it made sense. I've used the textarea trick before, but didn't think of it this time as i was too confused :-)

    Thanks for the clarification and your help! I'm glad it worked too ;-)

  • MartinB 411 posts 512 karma points
    Sep 11, 2010 @ 17:03
    MartinB
    0
  • Dwayne A 97 posts 117 karma points
    Jan 03, 2011 @ 22:31
    Dwayne A
    0

    Hej alle,

    Har også kigget efter samme løsning og læste en del forslag som jeg prøver af. Sidder med 4.2 og har haft syntax problemer. Mener, den Kim nævner ovenpå fungerer... indtil videre... så længe så godt.

    I hvert fald parser den i XSLT Visualizer. Kan få et fint file path, også et billedvisning ligefrem. Desværre bliver der returneret en nodeId i browseren.

    Har en xslt-fil, macro med kald fra Master template. Har oprettet media picker på doctypen, som ligger øverste i hierarkien (forsiden). Vil gerne oprette en banner, som kan skiftes af brugeren/administratoren vha media picker. Nu er der to ting, der skal løses:

    1. Billedet skal selvfølgelig vises fremfor nodeID.
    2. Hvordan kan jeg få alle children til at vise samme banner (globalt), uden at jeg skal oprette en media picker på alle doctyper?

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 03, 2011 @ 22:43
    Kim Andersen
    0

    Hi Dwayne.

    I'll take this one in english so that others can understand it as well. But you can go in danish if you preffer, that's up to you ;)

    Could you show us your XSLT code that generates this node id in the browser? That would make things a lot easier to explain and debug.

    /Kim A

  • Dwayne A 97 posts 117 karma points
    Jan 03, 2011 @ 23:02
    Dwayne A
    0

    Hey Kim. I'm new to the forum, and it didn't register I was writing in Danish until you answered. English is my native language, even. Crazy., ;~)

    Okay, here's the short and skinny. I've been trying to run the XSLT after your suggestion. Am I missing something else in the XSLT file or will this stand alone when grabbing, setting and rendering a pic from the Media Picker?

    <img src="{umbraco.library:GetMedia($currentPage/topBanner,0)/umbracoFile}" class="myClass" />

    Have also tried the Umbraco TV build exactly as they show it.

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

    Lastly, I've tried the following. Someone explained on another thread in this forum it's the 4.5 syntax:

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

    In any case, could I have forgotten a step in the dev process somewhere, or is it a question of missing/faulty code? Both?


  • Dwayne A 97 posts 117 karma points
    Jan 03, 2011 @ 23:19
    Dwayne A
    0

    ... also, Kim, I've even inserted the textarea you mentioned as a developmental curiosity. I get it to render in the Visualizer but absolutely nothing shows in the browser. I'm wondering if it isn't something I've missed in the DEV process, but the fact that the browser shows an ID puzzles me. The macro must be passing something to the template.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 04, 2011 @ 08:58
    Kim Andersen
    0

    Hi again Dwayne

    When you say that you are running on an Umbraco version 4.2 are you then meaning v4.0.2 or 4.5.2? As far as I know there has never been a 4.2 and the XML schema has changed in v4.5 (and the media XML actually again in 4.5.1).

    Is it this code that renders the id in the browser:

    <xsl:value-of select="$currentPage/topBanner"/>

    When you used the textarea, did you then see it on a page where there was an image selected in the topBanner-field?

    /Kim A

  • Dwayne A 97 posts 117 karma points
    Jan 04, 2011 @ 12:05
    Dwayne A
    0

    Kim,

    Yeah, that was a boner on my part - I meant 4.5.2. Latest version.

    Something else is obviously wrong. The text area does not appear to be reaching the browser - it is not visible in the source code at all. Any ideas?

    The XSLT might not be reaching the browser, but I still get the image nodeID in the browser, even when I comment all code in the XSLT. Could the id in the browser be coming from the media picker alone. Even when I comment all code in the xslt I still get the id in the browser.

    I have the following:
    topBanner.xslt with the attempts I've mentioned before. A topBanner macro and a master template with <umbraco:Item field="topBanner" runat="server">umbraco:Item>.

  • Dwayne A 97 posts 117 karma points
    Jan 04, 2011 @ 12:16
    Dwayne A
    0

    Hi again. I got it sorted. I had inserted a field instead of a macro into the macro assigned to the xslt. Now the picture and the textarea render in the browser.

    On child pages I receive: Error parsing XSLT file: \xslt\topBanner.xslt. I still want recursion to occur, so all children to the master receive the banner. Any help would be appreciated.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jan 04, 2011 @ 12:18
    Chriztian Steinmeier
    0

    Hi Dwayne,

    If topBanner is a macro you should be using <umbraco:Macro> instead of <umbraco:Item> - the "Insert Macro" button does that for you.

    /Chriztian

  • Dwayne A 97 posts 117 karma points
    Jan 04, 2011 @ 12:21
    Dwayne A
    0

    Hi Chriztian. Yeah, I figured that out right before you wrote. Thanks for the sharp eye ;~) I still want it recursive. See my previous post. Any help?

  • Dwayne A 97 posts 117 karma points
    Jan 04, 2011 @ 12:27
    Dwayne A
    0

    Hello again. I've simply inserted a recursive property to the macro. Is this best practice? It seems to do the trick, in any case. <umbraco:Macro Alias="TopBanner" runat="server" recursive="true">

Please Sign in or register to post replies

Write your reply to:

Draft