Skip to content
Eduardo Diaz edited this page Sep 19, 2016 · 2 revisions

PHP templates is the classic view template method supported since Joomla! 1.5. You can freely mix HTML and PHP to fine-tune the display of your view.

You should remember that this file is actually included by the view class. This means that $this is a reference to the View object and you have access to all of its public and protected methods and properties.

Loading sub-templates

Unlike Joomla!, you MUST NEVER use include or require to load a subtemplate. You can load any template from inside another template using the loadAnyTemplate method of the View class. Unlike include or require, loadAnyTemplate will honour Joomla! version suffixes and Joomla! template overrides.

$this->loadAnyTemplate('auto:com_example/Item/default_price');

This URI-like construct tells FOF where to look for your template file.

The schema (the part up to and including :) tells FOF which part of the application to look in:

  • site: Look in the frontend only
  • admin: Look in the backend only
  • auto: Look in the backend if we're running inside a backend application, otherwise look in the frontend
  • any: Look in both the frontend and backend. First we'll look inside the backend and then in the frontend if we're running inside a backend application, otherwise we will first look in the frontend and then in the backend.

The rest of this URI is the component name, view name and layout separated by forward slashes.

You must NOT specify the extension of the view template to load. FOF will automatically look for both classic PHP and Blade templates.

Loading XML forms

You cannot load XML forms using loadAnyTemplate. You also cannot load a form defined for another component, view or layout. What we're about to describe applies if you have both an XML form and a classic PHP view template for the same layout. For example, if you have both a default.php and a form.default.xml file for the same view.

Use the code

<?php echo $this->getRenderedForm(); ?>

to insert the XML form, rendered as HTML, anywhere you want in your classic PHP view template.

This construct allows you to customise the layout (e.g. adding information before/after the form) while still using the XML file to render the actual form.

HMVC

You will have to do an escape to PHP. For example:

<?php Container::getInstance('com_other', array(
    'tempInstance' => true,
    'input' => array(
        'view' => 'something',
        'task' => 'whatever',
        'other_something_id' => $this->item->other_something_id
    )))->dispatcher->dispatch(); ?>
Clone this wiki locally