21293 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 756 Views |
-
Static URLSegment?

7 May 2009 at 6:58am
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.
-
Re: Static URLSegment?

7 May 2009 at 9:53am Last edited: 7 May 2009 9:54am
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:$fields->addFieldToTab(
'Root.Content.Main',
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){
$fields->addFieldToTab(
'Root.Content.Main',
new TextField('MyIDField', 'Page-ID')
);
} else {
$fields->addFieldToTab(
'Root.Content.Main',
new ReadonlyField('MyIDField', 'Page-ID')
);
}
return $fields;
}
| 756 Views | ||
|
Page:
1
|
Go to Top |

