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

Uploading a file, and giving it a custom title


Go to End


1740 Views

Avatar
noizy

Community Member, 25 Posts

21 February 2007 at 10:29am

Okay, I worked through this problem yesterday with Sam's direct help, so thought it might be worthwhile posting here for future reference...

Required: the ability to attach a downloadable document to a page, and to give it a 'friendly' name for displaying.

So, step 1, set up the Page class...

<?

class Page extends SiteTree {
static $db = array(
"FileTitle" => "Text"
);
static $has_one = array(
"Download" => "File",
);
static $defaults = array(
);

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Download", new TextField("FileTitle"));
$fields->addFieldToTab("Root.Content.Download", new FileIFrameField("Download"));
return $fields;
}

}

class Page_Controller extends ContentController {

}

?>

...then, on the page.ss template...

<% if FileTitle %>
<a href="$Download.URL">$FileTitle</a>
<% end_if %>