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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

Outputting the URL of an uploaded file


Go to End


4 Posts   3239 Views

Avatar
Double-A-Ron

Community Member, 607 Posts

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

Avatar
Double-A-Ron

Community Member, 607 Posts

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.

Avatar
Double-A-Ron

Community Member, 607 Posts

14 June 2008 at 2:44pm

Right ho - I'm retarded.

Save and Publish

Avatar
spunktastica

Community Member, 2 Posts

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!