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.

General Questions

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

sitemap under 2.4


Reply

4 Posts   928 Views

Avatar
BigChris

7 July 2010 at 5:04am Community Member, 63 Posts

Hello,

I am using a modified version of the sitemap tutorial and have a question about the new URLsegment under version 2.4.

Function has been modified from the sitemap tutorial. But the $page->URLSegment is outputting the correct page name but as it is in some instances a sub page of a page, the parent page can be missing.

Any ideas?

Cheers
Chris

code below.

private function makeList($pages) {
$output = "";
if(count($pages)) {
$output = '
<ul id="sitemap-list">';
foreach($pages as $page) {
if(!($page instanceof ErrorPage) && $page->ShowInMenus && $page->Title != $this->Title){
$output .= '
<li><a href="'.$page->URLSegment.'" title="'.Convert::raw2xml($page->Title).' page">'.Convert::raw2xml($page->MenuTitle).'</a>';
$whereStatement = "ParentID = ".$page->ID;
//$childPages = new DataObjectSet();
$childPages = DataObject::get("Page", $whereStatement);
$output .= $this->makeList($childPages);
$output .= '
</li>';
}
}
$output .= '
</ul>';
}
return $output;
}

Avatar
Willr

7 July 2010 at 4:41pm Forum Moderator, 5511 Posts

Instead of using URLSegment there is now a method Link() which generates funnily enough the link to the page so use $page->Link() is what you want.

Avatar
BigChris

17 July 2010 at 11:44am Community Member, 63 Posts

Will,

Thank you for your reply. That solved it perfectly. Can I ask where can I find out about the new functionality is it in the api or docs?

Cheers
Chris

Avatar
Willr

17 July 2010 at 1:08pm Forum Moderator, 5511 Posts

A small note is available on the upgrading page - http://doc.silverstripe.org/upgrading:2.4.0#sitetree-_link_instead_of_sitetree-_urlsegment.