Jump to:

3444 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » Include contents of html-file choosen from FileFrameField in backend

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

Page: 1
Go to End
Author Topic: 1409 Views
  • jacobsjensen
    Avatar
    Community Member
    20 Posts

    Include contents of html-file choosen from FileFrameField in backend Link to this post

    Hi,

    I've created a new page type called IncludeHTML. In this pagetype I've added a File field, and a CMSfield of the type FileFrameField.
    This allows me to choose a html-file uploaded to the assests folder or upload one from my computer.
    My goal now is to get the contents of this html-file included in my IncludeHTML-template (IncludeHTML.ss) wherever I choose to put it. As an example $IncludeHTML ... should output the source code from the html-file chosen in the backend. This would ease my work load when including image maps etc.

    Any ideas on how to get this done in a neat way?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Include contents of html-file choosen from FileFrameField in backend Link to this post

    Could probably just do

    function IncludeHTML()
    {
    return file_get_contents(Director::baseFolder().'/'.$this->MyFileField()->Filename);
    }

  • jacobsjensen
    Avatar
    Community Member
    20 Posts

    Re: Include contents of html-file choosen from FileFrameField in backend Link to this post

    Hi, thank you for a rapid reply!
    Should I use <% includeHTML %> in the .ss file?
    Could you place the right MyFileField etc. in the code below for me (I'm new to all this!!)

    <?php
    /**
    * Defines the InkluderPage page type
    */
    class InkluderPage extends Page {
    static $db = array(
    );

    static $has_one = array(
    'FileInclude' => 'File'
    );

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

    class InkluderPage_Controller extends Page_Controller {
       function IncludeHTML()
          {
          return file_get_contents(Director::baseFolder().'/'.$this->MyFileField()->Filename);
          }
    }
    ?>

    1409 Views
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.