Jump to content

Method Page::template does not exist or is not callable


Recommended Posts

I have a page which is a subpage. So members/favorites for example.

In the favorites template I have some code for ajax responses. In other words `if ($config->ajax()) { ... }` which runs just fine.

I need to know the template of the page ID passed in because this same ajax is used from other templates, so slightly different code depending on which template we're on.

A page ID is sent over ajax, just the id, so I grab the page with `$item = $pages->get($pid);` where $pid is from the $input. All this works fine. I get the page object back. When I var_dump the object, I can see it has the template in there, i.e. "[template]=>'product'" because the ID belongs to a product the user has added to favorites.

Anyway, the problem is, I have this ID, I can get the Processwire page object, it has the template name listed in the var_dump, I can see it there, but when I try to access `$item->template()` I get this error.

"Fatal error:  Exception: Method Page::template does not exist or is not callable in this context (in /home/....../wire/core/Wire.php line 519)"

Why if I have a valid ID, and grab a valid $page object, can I not access $page->template() even when I can see the data is in the object?

Link to comment
Share on other sites

On 1/3/2020 at 6:40 PM, Gideon So said:

Hi @Vigilante,

I think the syntax should be $item->template.

Read the below page and look for template.



You're right, just wrong syntax, though I could swear I tried that. I was using the method style on a bunch of other stuff, must have got mixed up.


Sometimes it's the little things.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...