pinkp
pinkp

Reputation: 455

SilverStripe 3: How to display the URL Segment / Page info of a DataObject

I'm getting all my DataObjects from a specific class and displaying them randomly on another page. I need to access the URL segment of the page they belong to. How do I do this? I've tried, $URLSegment $UP.URLSegment $Parent.URLSegment etc which I can see why they would not work. I realise the dataobject does not have its own URL. I just need the URL of its page as this is its category.

PHP Function:

function Stockists()
{
$stockists = Stockist::get()->sort('RAND()');
return $stockists ? $stockists : false;
} 

Template

<% loop $Stockists %>
   $Title
   $URLSegment (does not work)
<% end_loop %>

Upvotes: 2

Views: 1821

Answers (1)

pinkp
pinkp

Reputation: 455

Thanks Mark Guinn. Turned out I could use

$StockistArea.URLSegment

as yes Stockist is the data object class and has a

 private static $has_one = array(
    'StockistArea' => 'StockistArea'
); 

to the StockistArea page! Hopefully this will help someone as I couldn't find anything on it.

Upvotes: 1

Related Questions