Jump to:

17452 Posts in 4473 Topics by 1971 members


SilverStripe Forums » Archive » Uploading a file, and giving it a custom title

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: 1068 Views
  • noizy
    Community Member
    25 Posts

    Uploading a file, and giving it a custom title Link to this post

    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 %>

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.