Documentation

Layouts

Directory Structures & Files

Views are written in PHP and HTML and have a .php file extension. View scripts are placed in /com_{componentname}/views/, where they are further categorized by the /{viewname}/tmpl. Within these subdirectories, you will then find and create view scripts that correspond to each controller action exposed; in the default case, we have the view script default.php.

/hubzero
  /components
    /com_{componentname}
      /views
        /{viewname}
          view.html.php
          /tmpl
            default.php

Overriding module and component presentation in templates is further explained in the Templates: Overrides section.

Creating A View

Joomla! 1.5 Method

The task of the view is very simple: It retrieves the data to be displayed and pushes it into the template. Data is pushed into the template using the JView::assignRef method.

<?php
 
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
 
jimport( 'joomla.application.component.view');
 
/**
 * HTML View class for the HelloWorld Component
 *
 * @package    HelloWorld
 */
 
class HelloViewHello extends JView
{
    function display($tpl = null)
    {
        $greeting = "Hello World!";
        $this->assignRef( 'greeting', $greeting );
 
        parent::display($tpl);
    }
}

HUBzero Method

Not necessary. Data retrieval and template assignment is handled in the controller.

Creating the Template

Joomla! templates/layouts are regular PHP files that are used to layout the data from the view in a particular manner. The variables assigned by the JView::assignRef method can be accessed from the template using $this->{propertyname} (see the template code below for an example).

Our template is very simple: we only want to display the greeting that was passed in from the view - this file is: views/hello/tmpl/default.php:

<?php
 
// No direct access
defined('_JEXEC') or die('Restricted access'); ?>
<h1><?php echo $this->greeting; ?></h1>

Last modified:

  • Copyright © 2022 Hubzero
  • Powered by Hubzero®