Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive

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

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

Outputting the URL of an uploaded file


Reply

4 Posts   1859 Views

Avatar
Double-A-Ron

14 June 2008 at 2:00pm Community Member, 604 Posts

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

Avatar
Double-A-Ron

14 June 2008 at 2:39pm Community Member, 604 Posts

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.

Avatar
Double-A-Ron

14 June 2008 at 2:44pm Community Member, 604 Posts

Right ho - I'm retarded.

Save and Publish

Avatar
spunktastica

20 June 2008 at 1:49am Community Member, 2 Posts

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!