Jump to:

23491 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Testing if on homepage

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: 1861 Views
  • losqualo
    Avatar
    Community Member
    17 Posts

    Testing if on homepage Link to this post

    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

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Testing if on homepage Link to this post

    <% if URLSegment = 'home' %>

    <% end_if %>

  • losqualo
    Avatar
    Community Member
    17 Posts

    Re: Testing if on homepage Link to this post

    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

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Testing if on homepage Link to this post

    Yes, sorry. My bad

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