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

PHP include producing strange result


7 Posts   508 Views


9 April 2012 at 7:53pm Community Member, 4 Posts

Hi everyone!

At the moment I have a site set up in in SS with:


   <% include Header %>
   <div id="main_content" class="container_12">

   <% include Footer %>


And if at any point I, for example, even call <? echo "hi"; ?> from within ANY <div> tags it will wrap another entire body around the rest of the site and the output will appear right at the top with the site's content pushed down by that much.

I gather this is something to do with the page now yet having fulling formed or something but does anyone have a decent explanation and solution to this problem?

Thanks very much!


9 April 2012 at 8:40pm Forum Moderator, 5511 Posts

You cannot embed PHP in SilverStripe templates. You should wrap your PHP in functions and pass the result to the template. For instance..


function SayHi() {
return "Hi";



9 April 2012 at 8:50pm Community Member, 4 Posts

I see, thank you!

This leads me to another question.

Say I make a new page type, say, "".

In the corresponding "Login.php" file may I place a function which in itself performs an include of another PHP script to receive its output?


9 April 2012 at 8:55pm Forum Moderator, 5511 Posts

Sure! If you haven't already I recommend doing tutorial 2 as that covers creating page types.


9 April 2012 at 9:07pm (Last edited: 9 April 2012 9:10pm), Community Member, 4 Posts

Yeah I've been going into overdrive with SS lately. I used to design stuff and code in PHP/HTML quite proficiently and it's not taken me very long to get to grips with most of this, which is a testament to the system!

Thanks for the quick replies.


9 April 2012 at 9:10pm Forum Moderator, 5511 Posts

Make sure that function is inside the Page_Controller or Page class (inside the { } parts).


9 April 2012 at 9:15pm Community Member, 4 Posts

Haha beat me to it! I realised pretty much as soon as I'd posted. Doh!