Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Outputting the URL of an uploaded file

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 1829 Views
  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Outputting the URL of an uploaded file Link to this post

    Hi all, I can't find anything on this in the Tutes, Forum or Doku, and I think I'm just going about it the wrong way.


    I have a field for uploading a PDF Dossier to a particular page type:

    class Tour extends Page {

       static $db = array(
       );
       

       static $has_one = array(
          'Dossier' => 'File'
       );

    ....

    Works fine, and I can upload a file, and see it present in the CMS.

    Now I am trying to output a link to that file in my template, but I can't figure out how to access the URL, or find any info on just what is available to this data type. Here are two things I have tried with no luck:

    <% control Dossier %>
    $URL // Also tried $Link
    <% end_control %>


    And one of the methods I found in the doku

    $Dossier.getURL


    The latter works to a certain degree. It outputs "http://domain.com/assets/". As too does:

    $Dossier.getFilename


    Can someone tell me how to output a link to an uploaded file in the template?

    Cheers
    Aaron

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: Outputting the URL of an uploaded file Link to this post

    Well, this post tells me that I am already on the right track and the problem is the page has no access to the file object:
    http://www.silverstripe.com/extending-hacking-silverstripe-forum/flat/516
    So here is the template code:

    <% if Dossier %>
       $Dossier.URL
    <% else %>
       No Dossier
    <% end_if %>


    "No Dossier" is displayed even when there is a file upload present in the CMS. First and most obvious problem would be a spelling error, but I have checked and re-checked, looks fine:

    class Tour extends Page {

       static $db = array(
       );

       static $has_one = array(
          'Dossier' => 'File'
       );
       

       
    function getCMSFields() {
       $fields = parent::getCMSFields();

       $fields->removeFieldFromTab( 'Root.Content.Main', 'Content');
       $fields->addFieldToTab( 'Root.Content.Main', new HTMLEditorField('TourTeaser', 'Tour
       $fields->addFieldToTab( 'Root.Content.Files', new FileIFrameField('Dossier', 'Upload and Attach Dossier PDF') );
       
       return $fields;
       }
       
    }


    Can anyone spot a problem with this? I definately can't. Is there a way to output all the data elements available to a page (like smarty)? It would make templating so much easier.

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: Outputting the URL of an uploaded file Link to this post

    Right ho - I'm retarded.

    Save and Publish

  • spunktastica
    Avatar
    Community Member
    2 Posts

    Re: Outputting the URL of an uploaded file Link to this post

    I'm still getting the same no PDF error and I DID save and publish!

    Was that the only error you had cause I don't have a clue on why mine isn't working!

    1829 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.