-
Notifications
You must be signed in to change notification settings - Fork 0
The Layout package
Joomla! 3.2 introduced a new concept for outputting reusable, overrideable, common blocks of HTML called JLayout. FOF 3 includes a helper class which allows you to render JLayouts easily.
The FOF way, from PHP templates:
FOF30\Layout\LayoutHelper::render($this->container, 'joomla.content.helloworld', [
'name' => 'Bob'
]);This substitutes Ye Olde Joomla! Way of doing:
$layout = new JLayoutFile('joomla.content.helloworld');
$data = array('name' => 'Bob');
echo $layout->render($data);On top of that, the LayoutHelper class will make sure that you're using FOF's conventions of template overrides to get
layout files. In simple terms, if you're calling it from the back-end it will try to load layouts from
administrator/layouts. Otherwise it will try to load layouts from the layouts directory. If you have a template
override of a layout then the override will be loaded.
Layouts are supposed to complement view templates, not replace them. They are only useful if you are dealing with blocks of output which should be reusable from outside your own component. If you have a common block which would be used from inside your component only you are strongly advised to use a regular PHP or Blade view template and use loadAnyTemplate to render it anywhere you want.
If you are providing a common block which should be used by extensions other than your component, without having to go through your Controller and View (HMVC) you should consider providing a JLayout instead. Keep in mind that this comes with some pitfalls:
- You have to install your files under the
layoutsdirectory of the site manually, using thefilepackage type. - You will have to educate your users that if they want to override the output of your component they will need to look
in two places,
components/com_something/View/something/tmplandlayouts/com_something. This is confusing to site integrators, hence our advice to avoid doing this unless strictly necessary.
There is, however, a good reason to use Joomla!'s own layouts in your components. These layouts will be overridden by
template developers to match their templates' styling. This is already used by Joomla! itself to render things like
editors, modal dialogs, the tollbar, quick icons and so on. If you're using JHtml to render something it already uses
JLayout under the hood. If you do not wish to use JHtml it's a good idea going through JLayout with the LayoutHelper
to get properly styled output.
Note: Apparently the JLayout system in Joomla! 3.2 and later is a port of (some of) the loadAnyTemplate functionality of FOF into the Joomla! core by a FOF and Joomla! contributor. We consider FOF's loadAnyTemplate functionality to be more flexible since it supports not only plain old PHP view templates but also Blade view templates and XML forms. Moreover, the loadAnyTemplate feature lets you specify more easily where to load each template and follows FOF's magic Factory conventions when the Magic or MagicSwitch Factory is in use, something that doesn't happen with JLayout.
FOF (Framework on Framework) and its documentation are Copyright © 2010-2020 Nicholas K. Dionysopoulos / Akeeba Ltd.
FOF is Open Source Software, distributed under the GNU General Public License, version 2 of the license, or (at your option) any later version.
The FOF Wiki content is provided under the GNU Free Documentation License, version 1.3 of the license, or (at your option) any later version.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license can be found on the GNU site.