Express entry page selector attribute

I have set up an Express Object for my v9 site which includes a Page Selector attribute. I am working on a custom template to display my Express Entry Listing which will include a link taken from the Page Selector Attribute.

Does the Page Selector attribute store the collection object with access to the Page Name and URL or is it simply the collection ID? I can output the collection ID for the page in the custom template using…

echo $result->getAttribute('page_link');

or I can output the name and link using…

echo $result->getAttributeValueObject('page_link');

Unfortunately I need to add a custom class to the anchor tag so cannot use this second option. I currently have it working by getting the page data from the collection ID but this seems a long way around for a potentially long list of entries…

$page_link = $result->getAttribute('page_link');
$page = \Page::getByID($page_link);
$pageURL = $page->getCollectionPath();
$pageTitle = $page->getCollectionName();

Is there any of accessing the collection data directly from the Page Selector attribute. Alternatively is there a way of injecting a class to the link which is generated in a similar way to adding a class to an image thumbnail e.g.

$page_link = $result->getAttributeValueObject('page_link');
$page_link = $page_link->addClass('button');
echo $page_link;

Any pointers would be gratefully received as I am sure there must be a more efficient way of achieving this.

Many thanks.

Yes, this is the correct way.
I would say you should be even more verbose and do some checks to not throw unintended errors:

$page_link = $result->getAttribute('page_link');
if (!empty($page_link)) {
    $page = \Page::getByID($page_link);
    if (!$page->isError() && !$page->isInTrash()) {
        $pageURL = $page->getCollectionPath();
        $pageTitle = $page->getCollectionName();
    }
}
1 Like

Thank you Parasek for looking into this - much appreciated. I will also implement the additional check to avoid unexpected errors.

Thanks
Paul

1 Like