Jump to:

3434 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » Page control using URLSegment

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

Page: 1
Go to End
Author Topic: 3550 Views
  • Ray Man
    Avatar
    Community Member
    4 Posts

    Page control using URLSegment Link to this post

    In past, i using <% URLSegment = item %> to control display item with i18n enable.
    In new 2.3.2 > , all page have unique URL and I cannot identify a page using URLSegment.

    All suggestion to fix this problem?

    How can I identify home home-1 home-2 as same page in template?

    Many Thank !!

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Page control using URLSegment Link to this post

    If you have different page types and you're trying to identify the page type (eg: HomePage extends Page [http://doc.silverstripe.com/doku.php?id=tutorial:1-building-a-basic-site#creating_a_new_page_type])

    Then doing:

    <% if Class = HomePage %>
    ...
    <% end_if %>

    should do what you want.

  • Ray Man
    Avatar
    Community Member
    4 Posts

    Re: Page control using URLSegment Link to this post

    But how to handle same type?

    I am in trouble after upgrade from 2.2.3 to 2.3.3.

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Page control using URLSegment Link to this post

    What do you mean by same 'type'?

    What exactly are you trying to do?

    If you want to identify a page type, then what i said in the last post is how to do it.

  • Ray Man
    Avatar
    Community Member
    4 Posts

    Re: Page control using URLSegment Link to this post

    Dear Pigeon,

    In past, I am using following method the create a hot item menu.
    I list target's children items identifed with URLSegment in i18n enironment.
    But in 2.3.3 seem I can't using this method again.

    <% control Menu(1) %>
    <% if URLSegment=xxx %>
    <% end_if %>
    <li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle</span></a></li>
    <% if Children %>
    <ul>
    <% control Children %>
    <li><a href="$Link" title="view page $Title" >$Title</a></li>
    <% end_control %>
    </ul>
    <% end_if %>
    </li>
    <% end_control %>

  • Ray Man
    Avatar
    Community Member
    4 Posts

    Re: Page control using URLSegment Link to this post

    I think may using create a new type to fix it. But I would like find another method without create new type of page. I have few sites using old method.

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Page control using URLSegment Link to this post

    Sorry, i have been without internet for the past few days.

    I'm not entirely sure what you are trying to do or why you are doing it. Using if URLSegment =xx is very bad because if the user changeds the URL in the CMS, your site will break.

    There should be some other way for you to do what ever it is.

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Page control using URLSegment Link to this post

    You could also consider to move the URLsegment control to the controller and let is return true if your URLsegment is home || home-1 || home-2, and then control that method in you template.

    When you do this in Page.php it will be rendered in all child page classes..

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