Jump to:

3397 Posts in 978 Topics by 854 members

Template Questions

SilverStripe Forums » Template Questions » PHP include producing strange result

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

Page: 1
Go to End
Author Topic: 427 Views
  • Quasso
    Avatar
    Community Member
    4 Posts

    PHP include producing strange result Link to this post

    Hi everyone!

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

    Page.ss:

    <head>

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

                $Layout
             
       
       <% include Footer %>

    etc

    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!

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: PHP include producing strange result Link to this post

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

    Page.php

    function SayHi() {
    return "Hi";
    }

    Page.ss

    $SayHi

  • Quasso
    Avatar
    Community Member
    4 Posts

    Re: PHP include producing strange result Link to this post

    I see, thank you!

    This leads me to another question.

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

    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?

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: PHP include producing strange result Link to this post

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

  • Quasso
    Avatar
    Community Member
    4 Posts

    Re: PHP include producing strange result Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: PHP include producing strange result Link to this post

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

  • Quasso
    Avatar
    Community Member
    4 Posts

    Re: PHP include producing strange result Link to this post

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

    427 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.