17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1386 Views |
-
Outputting the URL of an uploaded file

14 June 2008 at 2:00pm
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 -
Re: Outputting the URL of an uploaded file

14 June 2008 at 2:39pm
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. -
Re: Outputting the URL of an uploaded file

14 June 2008 at 2:44pm
Right ho - I'm retarded.
Save and Publish
-
Re: Outputting the URL of an uploaded file

20 June 2008 at 1:49am
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!
| 1386 Views | ||
|
Page:
1
|
Go to Top |


