Copied to clipboard

Flag this post as spam?

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


  • Dany Wu 81 posts 114 karma points
    Jul 26, 2009 @ 09:02
    Dany Wu
    0

    Inserting Media Picker property as a link in a template

    Hi folks,

    I think there's another similar thread not so long ago but nobody has answered it. I have succesfully done this with an image using ImageGen like this:

    <div style="width:300px;padding:5px;border: 1px dotted #ddd; margin-right: 10px; margin-bottom: 15px;">
             <a href="/umbraco/imageGen.aspx?image=<umbraco:Item field="mainImage" xslt="umbraco.library:GetMedia($currentPage/data[@alias='mainImage'], 'false')/data [@alias = 'umbracoFile']" runat="server"/>&width=600&constrain=true"
                                       rel="lightbox">
                                        <img src="/umbraco/imageGen.aspx?image=<umbraco:Item field="mainImage" xslt="umbraco.library:GetMedia($currentPage/data[@alias='mainImage'], 'false')/data [@alias = 'umbracoFile']" runat="server"/>&width=300&constrain=true"
                                             class="reflect rheight25 ropacity35"
                                             style="border:none;"/>
                                </a>
                        </div>

    It was a fairly straightforward but slightly painful to type out insertion.

    I tried to do the same thing with a link to a PDF file like below:

    <a href="<umbraco:Item field="pedigreePDF" xslt="umbraco.library:GetMedia($currentPage/data[@alias='pedigreePDF'], 'false')/data [@alias = 'umbracoFile']" runat="server"/>">Pedigree</a>

    All I get out of this one is - ">Pedigree - with no hyperlink, just text. If I didn't include the umbraco:Item in an <a> tag, just have:

    <td><umbraco:Item field="pedigreePDF" xslt="umbraco.library:GetMedia($currentPage/data[@alias='pedigreePDF'], 'false')/data [@alias = 'umbracoFile']" runat="server"/></td>

    ...then I get a path to the media file, "/media/949/Essie_pedigree.pdf"

    Kinda frustrating...can anyone see something wrong with my syntax? Is this the best practice for this requirement?

    Many thanks,
    Dany.

  • Dany Wu 81 posts 114 karma points
    Jul 26, 2009 @ 10:11
    Dany Wu
    0

    There must be some HTML rule I'm missing but this seems to work for me - no idea why:

    <a href="//<umbraco:Item field="pedigreePDF" xslt="umbraco.library:GetMedia($currentPage/data[@alias='pedigreePDF'], 'false')/data [@alias = 'umbracoFile']" runat="server"/>">Pedigree</a>

  • Martijn Maris 37 posts 235 karma points MVP
    Jul 26, 2009 @ 16:56
    Martijn Maris
    101

    In the wiki there is an example which uses concat to attach the <img> tag to the output of the GetMedia to show an image. Maybe you can use this also to create the <a> tag. Something like this:

    <umbraco:Item runat="server" field="pedigreePDF" xslt="concat('&lt;a href=&quot;',umbraco.library:GetMedia({0},'true')/data[@alias='umbracoFile'], '&quot; &gt;Pedigree&lt;a&gt;')" xsltDisableEscaping="true"/>

    The {0} in the XSLT will reference the pedigreePDF field. Then you do not need 'currentPage'. This will work in this example if pedigreePDF is a MediaPicker.

  • Dany Wu 81 posts 114 karma points
    Jul 26, 2009 @ 23:46
    Dany Wu
    0

    That's a much for elegant solution - thanks for that. I have a lot more to learn with XSLT obviously...

  • Peter Gregory 407 posts 1606 karma points MVP 3x admin c-trib
    Jul 27, 2009 @ 00:33
    Peter Gregory
    0

    Hey Danny

    Could you please mark Martijns post as the solution if you are using that. Thanks.

  • Alessione 3 posts 23 karma points
    Sep 09, 2010 @ 12:11
    Alessione
    0

    Hallo, I've tried this solution and it works thank you! but..

    what if I want to put in the link the name of the file???

    the link in the solution is hard coded and is 

     '&quot; &gt;Pedigree&lt;a&gt;'

    Pedigree.. I'll like to put instead the name of the media file to make it generic for every file....
    ...

    please help!!

     

    thanks

    Alessio

Please Sign in or register to post replies

Write your reply to:

Draft