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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Template Questions /

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

Include contents of html-file choosen from FileFrameField in backend


Go to End


3 Posts   2081 Views

Avatar
jacobsjensen

Community Member, 20 Posts

29 January 2009 at 10:03am

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?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

29 January 2009 at 10:34am

Could probably just do

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

Avatar
jacobsjensen

Community Member, 20 Posts

29 January 2009 at 10:44am

Edited: 29/01/2009 10:45am

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);
}
}
?>