Jump to:

23473 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Static URLSegment?

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: 856 Views
  • UncleCheese
    4085 Posts

    Static URLSegment? Link to this post

    Is there a way to have a static URLSegment for a given page? Sometimes I have to hardcode URLSegments into my template, and, although it's unlikely, it would be nice if I could be sure the client wouldn't change the title and mess things up.

  • banal
    Community Member
    901 Posts

    Re: Static URLSegment? Link to this post

    Hi UncleCheese.
    Well. You could use the Page ID, since that's immutable by your client. But this would fail if the client deletes the page and tries to re-create it.
    In the getCMSFields function you could make the ID visible for the user inside the CMS:

       new ReadonlyField('PageId', 'Page ID', $this->ID)

    And in the template you would do something like:

    <% if ID = 3 %>
    .. specific content for page with id 3 here ...
    <% end_if %>

    Another alternative could be a field that can only be written once.
    Here's an example how this could be done:

    public static $db = array(
       'MyIDField' => 'Varchar(64)'

    public function getCMSFields() {
       $fields = parent::getCMSFields();
       if($this->MyIDField == null){
             new TextField('MyIDField', 'Page-ID')
       } else {
             new ReadonlyField('MyIDField', 'Page-ID')
       return $fields;

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.