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.

Template Questions

Include contents of html-file choosen from FileFrameField in backend


Reply

3 Posts   1420 Views

Avatar
jacobsjensen

29 January 2009 at 10:03am Community Member, 20 Posts

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

29 January 2009 at 10:34am 4085 Posts

Could probably just do

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

Avatar
jacobsjensen

29 January 2009 at 10:44am (Last edited: 29 January 2009 10:45am), Community Member, 20 Posts

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