Search code examples
impresspages

How do I pull in page's "url path" field, via php, into the theme?


I'm trying to apply the page's url as a <div> id to be able to target some css on each individual page. After some characters cleanup I'm hoping to get <div id="test-page">.

I have tried pulling it in from the object that I get via

ipContent()->getBreadcrumb()

Unfortunately they are all (including one I need) protected and cannot be echoed out.

[urlPath:protected] => test-page/

Is there a function that I've missed and can use to pull that in? Or a proper method of getting it from the object? Cheers.


Solution

  • And of course, as soon as I posted a question I've found the answer:

    I could not get the protected value from [urlPath:protected] => test-page/ when doing this:

    $a = ipContent()->getBreadcrumb(); $a = $a[0]; $a = $a->urlPath;

    Solution: The way you can pull this is is by replacing $a->urlPath with $a->getUrlPath().

    It will work for all the elements in object. Like: $a->updatedAt; needs to be $a->getUpdatedAt();