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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Testing if on homepage


Go to End


8 Posts   7011 Views

Avatar
losqualo

Community Member, 17 Posts

2 September 2010 at 10:04pm

Hi,

Possibly dumb question, but is there a means of testing for whether the current page is the homepage? I'd like to modify the behaviour of an include for when on the homepage, and don't really want to create a homepage specific include to do the job. Something like

<% if home %>
...
<% endif %>

Been through the docs, but see nothing obvious... but then I'm still acclimatising to silverstripe

Thanks in advance

Rob

Avatar
Martijn

Community Member, 271 Posts

2 September 2010 at 10:44pm

<% if URLSegment = 'home' %>

<% end_if %>

Avatar
losqualo

Community Member, 17 Posts

4 September 2010 at 2:54am

Thanks... However

<% if URLSegment = 'home' %>

<% end_if %>

generates a syntax error due to an unexpected '}', which is odd.

If I remove the quotes from 'home', then all works OK.

Cheers

Rob

Avatar
Martijn

Community Member, 271 Posts

4 September 2010 at 9:23am

Yes, sorry. My bad :)

Avatar
Tiaan

Community Member, 4 Posts

4 June 2015 at 12:14am

Hi Guys, I am trying to accomplish the following: If the request is Home then display banner, otherwise just hide the banner.

i have tried this method
<% if URLSegment = home %>
<% include main-banner %>
<% end_if %>
But this does not do the trick for me.

Avatar
JonoM

Community Member, 130 Posts

4 June 2015 at 5:43am

Does that include work if you take away the <% if %> tags? I just notice it doesn't follow the regular naming scheme (MainBanner) but I suppose it shouldn't matter.

Avatar
Pyromanik

Community Member, 419 Posts

4 June 2015 at 8:34am

Another thing is that 3.x is more flexible in the templating engine.
So it pays to be more specific otherwise sometimes it can get confused.

<% if $URLSegment == 'home' %>

The other thing of course is that your homepage still needs to have the URL Segment set as home (if you don't - by default the site root will redirect to yoursite.com/my-homepage-changed-urlsegment )

Avatar
Tiaan

Community Member, 4 Posts

4 June 2015 at 5:21pm

Hi Guys, Thanks so much for the feedback :) Really Appreciate it, Here is what Ive done and seems to be working 110% now :D

<% if $URLSegment == 'home' %>
<% include MainBanner %>
<% end_if %>

I have tested the secondary pages and the banner is not displaying so this is perfect.,

Thanks again Guys.