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.

Template Questions /

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

Page control using URLSegment


Go to End


8 Posts   5261 Views

Avatar
Ray Man

Community Member, 4 Posts

26 August 2009 at 5:14am

Edited: 26/08/2009 5:15am

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 !!

Avatar
dhensby

Community Member, 253 Posts

26 August 2009 at 10:13am

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.

Avatar
Ray Man

Community Member, 4 Posts

28 August 2009 at 3:02am

But how to handle same type?

I am in trouble after upgrade from 2.2.3 to 2.3.3.

Avatar
dhensby

Community Member, 253 Posts

28 August 2009 at 9:11am

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.

Avatar
Ray Man

Community Member, 4 Posts

30 August 2009 at 4:50am

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

Avatar
Ray Man

Community Member, 4 Posts

30 August 2009 at 4:54am

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.

Avatar
dhensby

Community Member, 253 Posts

30 August 2009 at 1:42pm

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.

Avatar
Martijn

Community Member, 271 Posts

30 August 2009 at 1:43pm

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