Copied to clipboard

Flag this post as spam?

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


  • Jonathan Richards 3 posts 23 karma points
    Jan 24, 2011 @ 15:38
    Jonathan Richards
    0

    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('&lt;a href=&quot;',umbraco.library:GetMedia({0}, true())/umbracoFile, '&quot; /&gt;')" 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 "&#x00A0;"> ]>
    <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)" />

    <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

    <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

     

  • Magnus Eriksson 122 posts 362 karma points
    Jan 24, 2011 @ 16:13
    Magnus Eriksson
    0

    This:

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

    would result in an empty tag, maybe thats your problem? Try put some text in the a-tag:

    <umbraco:Item runat="server" field="Organogram" xslt="concat('&lt;a href=&quot;',umbraco.library:GetMedia({0}, true())/umbracoFile, '&quot;&gt;Link text&lt;/a&gt;')" xsltDisableEscaping="true"/>

    Regards,
    Magnus

  • Jonathan Richards 3 posts 23 karma points
    Jan 24, 2011 @ 17:13
    Jonathan Richards
    0

    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).

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 24, 2011 @ 18:35
    Jan Skovgaard
    0

    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

  • Jonathan Richards 3 posts 23 karma points
    Jan 24, 2011 @ 18:39
    Jonathan Richards
    0

    I am using Umbraco 4.5.2 and yes it is confusing: One of the reasons I've tried many different combinations.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 24, 2011 @ 18:48
    Jan Skovgaard
    0

    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

  • John C Scott 473 posts 1183 karma points
    Jan 25, 2011 @ 11:06
    John C Scott
    1

    A very simple way to use the upload file link would be

          <umbraco:Item 
    field="organogram"
    insertTextBefore="&lt;a href=&quot;"
    insertTextAfter="&quot; target=&quot;_blank&quot;&gt;"
    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 &lt;a href=&quot; 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.

     

  • FarmFreshCode 225 posts 422 karma points
    Apr 07, 2011 @ 20:00
    FarmFreshCode
    0

    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:

    <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

  • Rich Green 2246 posts 4008 karma points
    Apr 07, 2011 @ 20:49
    Rich Green
    0

    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

  • Daniel Bardi 927 posts 2562 karma points
    Apr 07, 2011 @ 20:52
    Daniel Bardi
    1

    If it's a media file use this:  (replace the 1234 with a variable if needed)

    <a href="{umbraco.library:GetMedia('1234',0)/umbracoFile}" target="_blank">View PDF</a>
  • FarmFreshCode 225 posts 422 karma points
    Apr 07, 2011 @ 20:55
    FarmFreshCode
    0

    @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..

  • Daniel Bardi 927 posts 2562 karma points
    Apr 07, 2011 @ 21:03
    Daniel Bardi
    0

    Previous post should be in an xslt macro.

    Do use inline, do this:  (where pdfMedia is your media picker property)

    <umbraco:Item field="pdfMedia" xslt="concat('&lt;a href=&quot;', umbraco.library:GetMedia({0},0)/umbracoFile, '&quot;&gt;View PDF&lt;/a&gt;')" runat="server" />
  • Rich Green 2246 posts 4008 karma points
    Apr 07, 2011 @ 21:03
    Rich Green
    0

    What Daniel said :)

  • FarmFreshCode 225 posts 422 karma points
    Apr 07, 2011 @ 21:35
    FarmFreshCode
    0

    Excellent addition Daniel.. thanks!

  • Thomas Egebrand Gram 63 posts 138 karma points
    Mar 19, 2012 @ 21:20
    Thomas Egebrand Gram
    0

    John C Scott's solution worked flawlessly for me, thanks a lot! :)

    // Thomas

  • Gus Deadman 45 posts 65 karma points
    Jun 29, 2012 @ 17:55
    Gus Deadman
    0

    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 

  • John C Scott 473 posts 1183 karma points
    Jun 29, 2012 @ 18:03
    John C Scott
    0

    Hi Gus - what data type is the "link" ?

  • Gus Deadman 45 posts 65 karma points
    Jun 29, 2012 @ 18:14
    Gus Deadman
    0

    "link" is a media picker property in the doc type.  

  • John C Scott 473 posts 1183 karma points
    Jun 29, 2012 @ 18:25
    John C Scott
    0

    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

  • John C Scott 473 posts 1183 karma points
    Jun 29, 2012 @ 18:38
    John C Scott
    0

    So you should be able to write:

    <umbraco:Item field="link" xslt="concat('&lt;a href=&quot;', umbraco.library:GetMedia({0},0)/umbracoFile, '&quot;&gt;View PDF&lt;/a&gt;')" 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.

  • John C Scott 473 posts 1183 karma points
    Jun 29, 2012 @ 18:44
    John C Scott
    0

    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" />


     

  • Gus Deadman 45 posts 65 karma points
    Jul 02, 2012 @ 12:33
    Gus Deadman
    0

    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('&lt;a href=&quot;', umbraco.library:GetMedia({0},0)/umbracoFile, '&quot;&gt;View PDF&lt;/a&gt;')" 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

     

  • John C Scott 473 posts 1183 karma points
    Jul 02, 2012 @ 12:37
    John C Scott
    0

    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 :(

  • John C Scott 473 posts 1183 karma points
    Jul 02, 2012 @ 12:45
    John C Scott
    0

    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 &lt;a href=&quot; 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

     


  • Gus Deadman 45 posts 65 karma points
    Jul 02, 2012 @ 12:58
    Gus Deadman
    0

    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

  • arronlee 2 posts 22 karma points
    Apr 26, 2013 @ 06:14
    arronlee
    0

    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

  • John C Scott 473 posts 1183 karma points
    Apr 26, 2013 @ 11:16
    John C Scott
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft