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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

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

Page Specific Content on Page.ss


Go to End


5 Posts   1507 Views

Avatar
plushtoy

Community Member, 10 Posts

6 October 2010 at 9:37am

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

Avatar
Willr

Forum Moderator, 5523 Posts

6 October 2010 at 8:26pm

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

Avatar
plushtoy

Community Member, 10 Posts

7 October 2010 at 2:50am

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

Avatar
Willr

Forum Moderator, 5523 Posts

7 October 2010 at 9:37am

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

Avatar
plushtoy

Community Member, 10 Posts

13 October 2010 at 3:26am

Worked like a charm. Thanks very much!