Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Variable includes

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1483 Views
  • UncleCheese
    Avatar
    4085 Posts

    Variable includes Link to this post

    Any way to do something like this?

    <% include $URLSegment_sidebar %>

    So I don't have to make a huge list like this?

    <% if InSection(about) %>
    <% include about_sidebar %>
    <% end_if %>

    < if InSection(news) %>
    <% include news_sidebar %>
    <% end_if %>

    Ugh.. seems a little unnecessary.

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Variable includes Link to this post

    yep I believe you should be able to use $URLSegment (as long as people don't go changing the urls )

    You might need to wrap the $URLSegment in curly braces {} so {$URLSegement}_sidebar to get it work.

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Variable includes Link to this post

    Usually it's not a generally safe idea to look for templates by a $URLSegment value in it, as it's far too dynamic - especially when you're giving the site to a client who could change page names, interrupting the $URLSegment value.

    And, AFAIK, there's currently no way to set in stone the page URLSegment value. A good reason to not is it's generally good SEO to make sure it's updated to reflect the content / title of the page.

    Again it depends on what application you're using SilverStripe for. If it's for yourself, no problem I guess. ;-)

    Sean

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