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:
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:
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.
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.
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>
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:
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.
That's a much for elegant solution - thanks for that. I have a lot more to learn with XSLT obviously...
Hey Danny
Could you please mark Martijns post as the solution if you are using that. Thanks.
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
'" >Pedigree<a>'
Pedigree.. I'll like to put instead the name of the media file to make it generic for every file....
...
please help!!
thanks
Alessio
is working on a reply...