Jump to:

22999 Posts in 11854 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » content from custom SS file not displayed in correct place

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

Page: 1
Go to End
Author Topic: 544 Views
  • Joefunkx
    Avatar
    Community Member
    4 Posts

    content from custom SS file not displayed in correct place Link to this post

    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.

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: content from custom SS file not displayed in correct place Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: content from custom SS file not displayed in correct place Link to this post

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

  • Joefunkx
    Avatar
    Community Member
    4 Posts

    Re: content from custom SS file not displayed in correct place Link to this post

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

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