Contents

Namespaces

Classes

Views have a special syntax for outputting escaped text. The standard way to
output escaped text in your views from li3 is as follows:

<?=$variable; ?>

This is where a lot of confusion comes in, because it is commonly misunderstood
that li3 depends on short_open_tags, however, that's not the case. The
contents of a view are processed through a tokenizer before
it is included by PHP. The file is then compiled into the final PHP+HTML (or whatever
other content type that is requested), which is then passed off to be fully rendered
by the two-step view to its final form.

The stream wrapper reads the file and searches for anything that looks like
<?=...?> and replaces it with <?php echo $h(...); ?>.

The design decision behind using PHP's short echo syntax is because it's a
familiar syntax and it helps developers focus more on what data should not be
escaped vs. what data needs to be escaped.

One special case situation to take important note of, is the use of
<?=$this->foo(); ?>. In this scenario, the code is translated to
<?php echo $this->foo(); ?> rather than being filtered through $h() as with
the former explanation. When direct access to a method or property on $this is
contained in the shorthands syntax, it will be output as normal without being
filtered. This is to make it easier to work with helpers that return markup.

Helpers are lazy-loaded by the current renderer. To use a helper, you can
reference it by its name like this:

echo $this->html->link('Example', 'http://www.example.com');

In a template, $this refers to the Renderer object. By using $this->html
for the first time, the renderer will create an instance of the helper and store
it so that the next time the helper is invoked the renderer will not have to
re-instantiate the helper.

Using such an approach, helpers can easily be loaded as needed without any
performance impact.

You can also create your own custom helper very easily by extending the Helper base class, and
placing your helper in the correct namespace. By default, helpers belong in the
<library>\extensions\helper namespace, but this can be changed through configuration (see the
the Libraries class). For example, consider the following class, saved as
extensions/helper/Custom.php:

Elements are reusable view snippets that you can use in several views and layouts.
You can reference it like so:

echo $this->_render('element', 'menu');

Where menu is the name of your element file, in this example views/elements/menu.html.php. When using $this->_render(), all of the variables set in the controller are available to the element template. You can pass variables declared in the view or additional static content using the third parameter to $this->_render():