Site Theme Paths
Permalink
Hi guys,
I am trying to get the current page id from the site_theme_path but doesn't seem to work. I am using the following code.
$page = Page::getCurrentPage();
echo $page->getCollectionID()
Im guessing its not working because this file loads before the view page?
cheers,
Ritch
I am trying to get the current page id from the site_theme_path but doesn't seem to work. I am using the following code.
$page = Page::getCurrentPage();
echo $page->getCollectionID()
Im guessing its not working because this file loads before the view page?
cheers,
Ritch
Thanks for replying Mnkras, I've had a look at the theme switcher, and yes its sort of what I want except I want to change theme on each section. Do you have any suggestions as how i should modify this block to make this happen?
cheers,
Ritch
cheers,
Ritch
yes this is really early in the dispatcher cycle, well before the request is parsed to see which page is being requested.
you could extend on_page_view event and do something like View::getInstance then I think setThemeToRender or SetTheme or something really close to that from there.
Thanks for the suggestion Scott, I'm not a php developer, let alone experienced with an MVC framework, i just dabble with php so I'd appreciate any code samples and what files I should be looking at.
I did a quick hack in the site_theme_path and just split the url and did a switch statement that does a setTheme for that section.. i know its crap lol...I would like to do this the correct way though.
I did a quick hack in the site_theme_path and just split the url and did a switch statement that does a setTheme for that section.. i know its crap lol...I would like to do this the correct way though.
if it works, then that's good, right? :)
Otherwise, you'd want to enable application events, register a model or library for it to receive on_page_views..so basically then at that point the event is passed the page that is being rendered, and you can set the theme for that page view right before it is being rendered.
The extending on_page_view event is the way one would do it if you were delivering code to a paying client, but for something for yourself or something so site specific where doing events extending and stuff is overkill then I personally think you were very pragmatic in your thinking since your solution works.. and solving problems as quickly as possible with the least amount of effort is a very good thing :)
-Scott
Otherwise, you'd want to enable application events, register a model or library for it to receive on_page_views..so basically then at that point the event is passed the page that is being rendered, and you can set the theme for that page view right before it is being rendered.
The extending on_page_view event is the way one would do it if you were delivering code to a paying client, but for something for yourself or something so site specific where doing events extending and stuff is overkill then I personally think you were very pragmatic in your thinking since your solution works.. and solving problems as quickly as possible with the least amount of effort is a very good thing :)
-Scott
if your trying to set the theme based on the page, look how the theme switcher addon does it,