2985 Posts in 761 Topics by 740 members
Template Questions
SilverStripe Forums » Template Questions » Control a page by ID rather than URL?
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba
|
Page:
1
|
Go to End | |
| Author | Topic: | 1280 Views |
-
Control a page by ID rather than URL?

19 May 2010 at 7:31am
In my templates, how would I add specific page control by ID rather than URL? eg.
<% control Page(PageID) %>
<% control ChildrenOf(PageID) %>
On a couple of occasions a client will inadvertently break these links by changing the page title (and/or the meta title) - so controlling by URL is not always ideal.
Any ideas?
-
Re: Control a page by ID rather than URL?

19 May 2010 at 6:26pm
You could write a function that does that for you quite easily.
Place this in your Page class:function PageById($id){
return DataObject::get_by_id("SiteTree", (int)$id);
}Then in your template you can access pages by id like this:
<% control PageById(1) %>$Title<% end_control %>
-
Re: Control a page by ID rather than URL?

12 June 2010 at 10:28am
thank you this has helped me out a lot.
-
Re: Control a page by ID rather than URL?

30 June 2010 at 8:57am
You can also just simply use the ID in place of the URLSegment,ie:
<% control childrenOf(20) %>
| 1280 Views | ||
|
Page:
1
|
Go to Top |



