3214 Posts in 848 Topics by 810 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 268 Views |
-
PHP include producing strange result

9 April 2012 at 7:53pm
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!
-
Re: PHP include producing strange result

9 April 2012 at 8:40pm
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
-
Re: PHP include producing strange result

9 April 2012 at 8:50pm
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?
-
Re: PHP include producing strange result

9 April 2012 at 8:55pm
Sure! If you haven't already I recommend doing tutorial 2 as that covers creating page types.
-
Re: PHP include producing strange result

9 April 2012 at 9:07pm Last edited: 9 April 2012 9:10pm
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.
-
Re: PHP include producing strange result

9 April 2012 at 9:10pm
Make sure that function is inside the Page_Controller or Page class (inside the { } parts).
-
Re: PHP include producing strange result

9 April 2012 at 9:15pm
Haha beat me to it! I realised pretty much as soon as I'd posted. Doh!
| 268 Views | ||
|
Page:
1
|
Go to Top |


