I’ve setup a select field in a blueprint which displays a list of subpages which use a specific template which is working well, however after researching and trying some options I cannot figure out how to retrieve the full URL to the selected subpage for use within a template.
To get around this, I’ve done the below which is giving me the correct URL but wondering if there is a better / cleaner way?
Not 100% sure if the comma is needed here as a parameter in the toPage() function. I usually use the pages field instead of a select field to select pages.
Ahhh, I didn’t even see the pages field, I thought I had to query via a select field. I’ve just updated the blueprint to use a pages field which is working perfectly.
In the template I’m tried using the e() helper to check if the field exists before outputting the value but I’m getting a ‘Call to a member function url() on null’ error when appending url() to the value string:
Do I receive the error because I need to convert the page to a page object using the toPage method before being able to output its URL? If so, how would I go about doing this within the e() helper or is this not possible?
When I omit url() I effectively output a relative URL but I was aiming to output the absolute URL:
The e() helper is not useful here, you have to use an if statement like I posted above (only I was very stupid and wrote toFile() when I meant toPage(), but this is corrected now.
You don’t have to check if the field exists or contains a value in this case, because we have to make sure that we have a page object, so even if the field exists and is not empty, we cannot be sure the page hasn’t been deleted in the meantime. And if the field is empty, the check for the page object will return false anyway.
So please use the if statement I posted above.
And your link should go inside the if statement, because you don’t want a link if there is no url (plus your $projecturl would be undefined and throw an error if the page doesn’t exist).