Jump to:

5514 Posts in 1733 Topics by 1219 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Page Specific Content on Page.ss

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

Page: 1
Go to End
Author Topic: 991 Views
  • plushtoy
    Avatar
    Community Member
    10 Posts

    Page Specific Content on Page.ss Link to this post

    Hi There,

    Is there a way to add content to templates/Page.ss that will only display if a user is on a specific page?

    If user is on the news page, display this <h1>Hello world</h1>

    A simple work around would be the best as I am new to this.

    Thanks,
    plush

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Page Specific Content on Page.ss Link to this post

    A number of ways to do it, each with varying degrees of usefulness

    <% if URLSegment = news %>
    .. on news
    <% end_if %>

    Do you have a php page type for news pages? Then you could do

    <% if ClassName = NewsPage %>
    .. on news
    <% end_if %>

    Which is more robust. Or you could setup a NewsPage.ss template to have it

  • plushtoy
    Avatar
    Community Member
    10 Posts

    Re: Page Specific Content on Page.ss Link to this post

    Hey Willr,

    This works great! I do have multiple news page types. NewsHolder, NewsLandingPage, NewsPage, Newsroom.

    Is there a way to have the content display only on these page types?

    plush

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Page Specific Content on Page.ss Link to this post

    Then you could do something like this on your Page.php

    function IsNewsPage() {
    $news = array('NewsHolder', 'NewsLandingPage', 'NewsPage', 'Newsroom');

    return (in_array($this->ClassName, $news));

    And then you can use <% if IsNewsPage %>...

  • plushtoy
    Avatar
    Community Member
    10 Posts

    Re: Page Specific Content on Page.ss Link to this post

    Worked like a charm. Thanks very much!

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