Passing data to a page template.

Permalink
I'm trying to find a way to pass data to a page template. I'm use to how things work in a block, where there's a controller and you can pass data with $this->set.

But with page templates in a theme, how does one go about passing data to the page any time its viewed?

ob7dev
 
JohntheFish replied on at Permalink Reply
JohntheFish
If a controller has $this->set available, then anywhere the controller is available you can do something like:
extract ( $this->controller->getSets() );


I have not used it in the context you describe, but often use it to minimnise parameter arrays passed to elements.
ob7dev replied on at Permalink Reply
ob7dev
Well what I'd like to do is have one controller loading anytime a page is loaded, and that controller pass data to the page template. Not sure how to do this yet.

And where does a page template inherit its classes from? I can use things like Config::get from a page template, but using a custom class is obviously not available. So where are page templates inheriting from, which controller is running the show?
Gondwana replied on at Permalink Reply
Gondwana
There's a diagnostic/cheat I've used a few times, which involves printing (or logging) the type of $this. I can't recall the syntax off the top of my head.
Gondwana replied on at Permalink Reply
Gondwana
Try something like
echo "I'm an object of class " , get_class($this) , "\n";


Or if that isn't visible, log it.
ob7dev replied on at Permalink Reply
ob7dev
From a page template:
I'm an object of class Concrete\Core\Page\View\PageView
:) Thanks for the trick.