开发者

SilverStripe PHP overriding $Layout variable

Hey... how can I override $Layout variable. I would like to add some logic so if a user is logged in it shows content X if not content Y. I tried defining Layout function inside Page.ph开发者_JAVA技巧p but it does not work. Thx.


I don't think you really want to override the $Layout function... this is used to include an appropriate template for the page type.e.g. if you had a page type with a class name of NewsPage then SilverStripe would check inside the templates/Includes directory for a NewsPage.ss file. If that didn't exist then it would use the Page.ss file in that directory along with the Page.ss in the root of the templates directory (which has the $Layout variable) See SilverStripe Templates.

If you're wanting to show different content then one way would be to override the Content variable. You could do this by overriding the index() function like so (add this to your controller):

function index($request) {
    if( Member::currentUserID() ) {
        return array(                    
            'Content' => '<p>My custom content</p>'
        );
    } else {
        return array();
    }
}

Another way would be to do this in the template itself like this:

<% if CurrentMember %>
    <p>Logged in</p>
<% else %>
    <p>No logged in</p>
<% end_if %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜