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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

content from custom SS file not displayed in correct place


Reply


4 Posts   654 Views

Avatar
Joefunkx

Community Member, 4 Posts

1 October 2010 at 2:59am

Edited: 01/10/2010 3:59am

Hey guys,
I followed the "Extending Silverstripe" Tutorial and created an additional page type - CustomPage.

I put the CustomPage.php file in the mysite/code folder with the following:

<?php
/**
*/
class CustomPage extends Page {
static $db = array(
);
static $has_one = array(
);
}

class CustomPage_Controller extends Page_Controller {

function showstuff(){
echo "hi!";
}
}
?>

I put a simple echo statement in my new function "showstuff()" to test with.

Then I added CustomPage.ss to the template/layout folder, and it contains:

$showstuff

But the problem is, "Hi!" is displayed ABOVE anything else on the page (header, content divs, etc.).

If I put some text inside the CustomPage.ss file, it displays in the correct content portion of the page. So for some reason when it calls the function it seems to lose where it is on the page.

Avatar
swaiba

Forum Moderator, 1805 Posts

1 October 2010 at 11:24pm

Hi,

What is the full path of the template you are using and which theme are you using... Maybe if the site is small it might be worth uploading your mysite and theme folder as it could be to do with the location of the templates. Another thing to try is a complete refresh (i.e. instead of just a dev build) create a 'silverstripe-cache' folder in your webroot to ensure it uses that as the cache and then you can delete the contents of the cache to enforce a complete refresh.

Barry

Avatar
Willr

Forum Moderator, 5513 Posts

2 October 2010 at 10:45pm

You shouldn't echo anything. Instead use return "hi"; if you use echo it echos immediately hence before SilverStripe complies the template.

Avatar
Joefunkx

Community Member, 4 Posts

5 October 2010 at 7:42am

Willr, Thanks! that worked. I may post again once I put my actual PHP code in, if I run into any problems