I am trying to choose the layout for my view dynamically, which is what I imagined setLayout
or loadTemplate
on my JViewLegacy
view would be able to do, but there seems to be some extra convention going on here that I can't seem to follow.
If my structure looks like this:
views/myview/view.html.php
views/myview/tmpl/default.php
views/myview/tmpl/alternate.php
And then in my class I have something like this:
class MyComponentViewMyView extends JViewLegacy {
function display($tpl = null ) {
if ( ViewManager::$showAlternate ) {
$this->setLayout('alternate');
}
parent::display($tpl);
}
}
What I would expect from the documentation I have been able to find is that this would load the view from 'alternate.php' instead of 'default.php' but instead I get a message like this: 500 Layout default_alternate not found.
Things that I have found recommended and tried that don't seem to have made a difference, or the only difference they have made was a slight change of error message, usually to Layout default not found
:
- Changing from
setLayout
toloadTemplate
. - Just using the
layout
parameter in the URL to test if it can be found. - Renaming
alternate.php
todefault_alternate.php
or evenalternate_default.php
- Changing the path to
/view/myview/alternate/default.php
instead of/view/myview/tmpl/default.php
- Calling
setLayout
withdefault:alternate.php
instead.
There is clearly something I have missed or not been able to find in the documentation. What do I need to do to be able to render alternate.php
instead of default.php
for the same view?