I wish to complete something, that I thought would have been relatively straight forward, yet, due to inexperience with Umbraco, I find myself unable to solve using the online help.
I wish to place a hyperlink on the home page to a pdf file. I wanted the pdf file to be stored within the umbraco's content managament system so that content editors could change the pdf at a later date. To this end, I have uploaded the pdf twice, to the backend: Once as a property of the home page (After adding a generic property to the document type of the home page of type Upload), and Twice; uploaded a file directly under the media section. Both I have called Organogram.
I have then edited the Template for the Home Page with a variety of code including:-
Thanks for the reply Magnus, sadly still nothing is outputted when I embed 'Link Text' within the a tag (I copied & pasted your text directly into the template for the home page).
What version of Umbraco are you in fact using? Your inline example makes use of the new XML schema, which was introduced in Umbraco 4.5 and the one using a macro is using the legacy schema syntax.
As a newbie this is of course a bit confusing when one is searching for code samples to use. Therefore it's easier to help you out if you can tell us what version of Umbraco you're working with.
Well in that case you're making use of the new schema. If you for some weird reason would like to make use of the old XML schema you can change it in the UmbracoSettings.config file. But I don't recommend it in your case.
Before I forgot to ask if you have uploaded the PDF file into the media library? If so are you using a media picker on your document type? Or have you made an upload field directly on your frontpage document type?
The best thing is you don't have to type this in and risk getting the syntax wrong, you can click the "Insert Umbraco Page Field" button in your template ( ) and a friendly dialogue will allow you to select your field you want to add, and allow you to type in the text you want to appear before and after, it will do the html encoding too so you don't have to type <a href=" you can type just <a href=" etc.
However to use the link to the file in the media library you would need to use a mediapicker in your document type. You could then either use an xslt macro to get a nice link or inline xslt and the getMediaItem and pass the ID from the current page.
I would rather just link to the PDFs ID number which happens to be (1234). This would allow me to update the file later on and not have to update the link. I feel like I need to use the GetMedia reference but I have't seemed to make it work yet.
What is the best way to link to static documents within your media section? If you could supply a code snippit that I can use to replace my existing one above that would be great. Thank you
I want to do almost the same thing as original poster and see the responses and the one marked as an answer however I'm not sure how to use this code. I've tried using it in the template and nothing happens except if I use this;
<umbraco:Item field="link" runat="server" />
This just returns the node name, which is good as I presume I use that somewhere to form the link. What should I do with it? I tried using it in NiceURL but didn't get that right. Do I need to create a macro?
and equivalent to what might be inside an <xsl:value-of select="..."/>
There's always value though in having it in the template and not a macro if that will over complicate the solution, however a nice maco is always better if appropriate.
the concat(,,,) xslt function will take any number of strings and joni them together and so form your link for you
and the umbraco.library:GetMedia() is one of the many very useful xslt extentions for umbraco that will take a media id and return some data about it of which /umbracoFileName is a part
the {0} inside that function is C# string.format() style syntax saying use the zeroth provided attribute which in this implenetation means the contents of the field="" attribute
maybe a marginally cleaner / easier to read / write way to write this could be
modelled on the way the image tag is used in the same page.
Thanks for your help, we got there in the end.
BTW for anybody else needing this, "link" is a mediapicker property added to the DocType which allows the content editor to choose a media file so could be used for any file type, in this case a PDF.
Hi Arron, Welcome to our forum, I'm not entirely sure that this would be appropriate. There are much simpler ways to add this function to an Umbraco site than adding this control. HTH, John
Linking pdf file from home page
Hi all,
Noob user here.
I wish to complete something, that I thought would have been relatively straight forward, yet, due to inexperience with Umbraco, I find myself unable to solve using the online help.
I wish to place a hyperlink on the home page to a pdf file. I wanted the pdf file to be stored within the umbraco's content managament system so that content editors could change the pdf at a later date. To this end, I have uploaded the pdf twice, to the backend: Once as a property of the home page (After adding a generic property to the document type of the home page of type Upload), and Twice; uploaded a file directly under the media section. Both I have called Organogram.
I have then edited the Template for the Home Page with a variety of code including:-
<umbraco:Item Field="Organogram" runat="server"></umbraco:Item>
and
<umbraco:Item runat="server" field="Organogram" xslt="concat('<a href="',umbraco.library:GetMedia({0}, true())/umbracoFile, '" />')" xsltDisableEscaping="true"/>
and
<umbraco:Macro Alias="ShowOrganogram" runat="server"></umbraco:Macro>
(which links to a xslt file containing
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets PS.XSLTsearch ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:variable name="media" select="umbraco.library:GetMedia(./data [@alias='Organogram'], 0)" />
<a target='_blank' href='{$media/umbracoFile}'>
</a>
</xsl:template>
</xsl:stylesheet>
- this xslt will not even save)
The only thing I have found to work within the template is hardcoding
<a href="/media/7043/emo org chart.pdf" target="_blank">
So my question is, how do I output either generic properties of a document or media from the media section?
I am using Umbraco 4.5.2
Thanks
This:
would result in an empty tag, maybe thats your problem? Try put some text in the a-tag:
Regards,
Magnus
Thanks for the reply Magnus, sadly still nothing is outputted when I embed 'Link Text' within the a tag (I copied & pasted your text directly into the template for the home page).
Hi Jonathan
What version of Umbraco are you in fact using? Your inline example makes use of the new XML schema, which was introduced in Umbraco 4.5 and the one using a macro is using the legacy schema syntax.
As a newbie this is of course a bit confusing when one is searching for code samples to use. Therefore it's easier to help you out if you can tell us what version of Umbraco you're working with.
Cheers
/Jan
I am using Umbraco 4.5.2 and yes it is confusing: One of the reasons I've tried many different combinations.
Hi again
Well in that case you're making use of the new schema. If you for some weird reason would like to make use of the old XML schema you can change it in the UmbracoSettings.config file. But I don't recommend it in your case.
Before I forgot to ask if you have uploaded the PDF file into the media library? If so are you using a media picker on your document type? Or have you made an upload field directly on your frontpage document type?
/Jan
A very simple way to use the upload file link would be
<umbraco:Item
field="organogram"
insertTextBefore="<a href=""
insertTextAfter="" target="_blank">"
runat="server" />
The best thing is you don't have to type this in and risk getting the syntax wrong, you can click the "Insert Umbraco Page Field" button in your template ( ) and a friendly dialogue will allow you to select your field you want to add, and allow you to type in the text you want to appear before and after, it will do the html encoding too so you don't have to type <a href=" you can type just <a href=" etc.
However to use the link to the file in the media library you would need to use a mediapicker in your document type. You could then either use an xslt macro to get a nice link or inline xslt and the getMediaItem and pass the ID from the current page.
I think I have a similar noob question. (I'm using v4.7 by the way)
Right now I have my naivagation in an XSLT file. But to link to a PDF file which I have loaded in my Media section I am using the following code:
<a href="/media/1501/cohpa_org_chart_4-11.pdf" target="_blank">
I would rather just link to the PDFs ID number which happens to be (1234). This would allow me to update the file later on and not have to update the link. I feel like I need to use the GetMedia reference but I have't seemed to make it work yet.
What is the best way to link to static documents within your media section? If you could supply a code snippit that I can use to replace my existing one above that would be great. Thank you
You need to use nice url, something like this in XSLT
<a href="{umbraco.library:NiceUrl(@id)}" target="_blank">
This means regardless of renaming your pdf, the link will always work.
Rich
If it's a media file use this: (replace the 1234 with a variable if needed)
@Rich Green That works great for content pages, but not when I am trying to call an document that I have uploaded into my media section.
@Daniel Bardi - I would swear I had already tried that solution.. but sure enough it worked great this time.. THANK YOU.. that was driving me nuts..
Previous post should be in an xslt macro.
Do use inline, do this: (where pdfMedia is your media picker property)
What Daniel said :)
Excellent addition Daniel.. thanks!
John C Scott's solution worked flawlessly for me, thanks a lot! :)
// Thomas
I want to do almost the same thing as original poster and see the responses and the one marked as an answer however I'm not sure how to use this code. I've tried using it in the template and nothing happens except if I use this;
<umbraco:Item field="link" runat="server" />
This just returns the node name, which is good as I presume I use that somewhere to form the link. What should I do with it? I tried using it in NiceURL but didn't get that right. Do I need to create a macro?
Thanks
Hi Gus - what data type is the "link" ?
"link" is a media picker property in the doc type.
the answer for Jon was for an Upload data type
you can convert a media picker into a link using inline xslt in the template or do this in an xslt macro
can't think of the syntax off the top of my head but i'll look it up and let you know
So you should be able to write:
<umbraco:Item field="link" xslt="concat('<a href="', umbraco.library:GetMedia({0},0)/umbracoFile, '">View PDF</a>')" runat="server" />
To be fair this is a bit hacky. So the XSLT above is HTML encoded so that it can be in the attribute. Really this would be :
concat('<a href="', umbraco.library:GetMedia({0},0)/umbracoFile, '">;View PDF</a>
and equivalent to what might be inside an <xsl:value-of select="..."/>
There's always value though in having it in the template and not a macro if that will over complicate the solution, however a nice maco is always better if appropriate.
mean't to add too that there are 2 parts to this
the concat(,,,) xslt function will take any number of strings and joni them together and so form your link for you
and the umbraco.library:GetMedia() is one of the many very useful xslt extentions for umbraco that will take a media id and return some data about it of which /umbracoFileName is a part
the {0} inside that function is C# string.format() style syntax saying use the zeroth provided attribute which in this implenetation means the contents of the field="" attribute
maybe a marginally cleaner / easier to read / write way to write this could be
<umbraco:Item field="mediaPicker"
insertTextBefore="<a href=""
insertTextAfter="">Link PDF</a>" xslt="umbraco.library:GetMedia({0},0)/umbracoFile"
runat="server" />
Thanks for the swift and full reply, though I'm not quite clear how I should use the suggestions.
I used this in the template as recommended;
<umbraco:Item field="link" xslt= "concat('<a href="', umbraco.library:GetMedia({0},0)/umbracoFile, '">View PDF</a>')" runat= "server" />
Which showed this on the final page as the text;
<a href="/media/2652/Brand Sitemaps and Wireframes 20120522 - Site Map 1.pdf">View PDF</a> .
This is the correct address for the PDF but needs to be as code for the link to work.
I then tried this in the template;
concat('<a href="', umbraco.library:GetMedia({0},0)/umbracoFile, '">;View PDF</a>
Which gave this n the browser;
concat(';View PDF
The link gave an error
I finally tried this in the template;
<umbraco:Item field="mediaPicker"
insertTextBefore="<a href=""
insertTextAfter="">Link PDF</a>" xslt="umbraco.library:GetMedia({0},0)/umbracoFile"
runat="server" />
Which resulted in displaying this;
Link PDF" xslt="umbraco.library:GetMedia({0},0)/umbracoFile" runat="server" />
as text.
Not sure what I'm doing wrong.
Regards
i think the issue in the above is ~ and this may be bad copy and pasting on my part - you'd think i'd have the hang of that by now :)
the media picker data type property you created on your document type I think is called "link"
so in field="" this should be link
where is is field="mediaPicker" this is the name I gave my media picker when I was testing what I wrote to you :(
aaah also I can see another thing... in the output you are getting the actual text <a href="lalalaaaa".... ?
ie the output is html encoded (if you view source you see <a href=" etc.)
yes by default the output from umbraco:Item will be html encoded
luckily there is XsltDisableEscaping="true" for just this proper ocassion
so... the whole thing might look now like:
<umbraco:Item field="link"
insertTextBefore="<a href=""
insertTextAfter="">Link PDF</a>" xslt="umbraco.library:GetMedia({0},0)/umbracoFile"
XsltDisableEscaping="true"
runat="server" />
it's worth saying again though that this is a bit hacky
it's better to use a macro unless this really is just one or two links in your master page / template
I'm afraid that still gives me;
Link PDF" xslt="umbraco.library:GetMedia({0},0)/umbracoFile" XsltDisableEscaping="true" runat="server" />
as text on the page.
I've been playing about with all the suggestions and just finally got it to work with;
"<a href='<umbraco:Item field="link" xslt="umbraco.library:GetMedia({0},0)/umbracoFile" runat="server"></umbraco:Item>' />Link PDF</a>"
modelled on the way the image tag is used in the same page.
Thanks for your help, we got there in the end.
BTW for anybody else needing this, "link" is a mediapicker property added to the DocType which allows the content editor to choose a media file so could be used for any file type, in this case a PDF.
Cheers
I am a newcomer to this forum, so I am not sure whether I understand your question correctly.
Are you asking for Linking pdf file from home page?
Have you ever thought about re-editing a control to help you according to your own requirements?
If not , I hope you can have a try. I do think this PDF control is pretty a genius. It saves me a lot of time.
What's more, Yiigo offers many free trials of different plugins dealing with different files of documents.
i do hope it will be helpful.
Bset Regards
Arron
Hi Arron, Welcome to our forum, I'm not entirely sure that this would be appropriate. There are much simpler ways to add this function to an Umbraco site than adding this control. HTH, John
is working on a reply...