- Special syntax
This is where a lot of confusion comes in, because it is commonly misunderstood that Lithium depends on `short_open_tags`, however, that's not the case. The contents of a view are processed through a [tokenizer](template/view/Compier) before it is included by PHP. The file is then `compiled` into the final PHP+HTML (or whatever other content type that is requsted), which is then passed off to be fully rendered by the two-step view to its final form.
See the PHP [manual](http://php.net/manual/en/book.tokenizer.php) to learn more about tokens.
The stream wrapper reads the file and searches for anything that looks like `` and replaces it with ``.
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 `foo()?>`. In this scenario, the code is translated to `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.
An example would be something like:
- Note:** `$h()` is the HTML escape function used in views.
- Note:** To output regular, unescaped text, use plain old ``.
- Other useful information:**
- [Introduction to PHP streams](http://www.php.net/intro.stream) - [Stream examples](http://www.php.net/stream.examples)
- Using helpers
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.
- More info**
- [ HTML helper](template/helper/Html) - [ Form helper](template/helper/Form) - [ Helper base class](template/Helper)
- Creating custom helpers
You can then use your helper in templates as follows:
Your custom helper will then be auto-loaded into the templating engine from your application or a plugin.
- Extending core helpers
For example, to add or replace methods in the `Form` helper, you can add the following to `app/extensions/helper/Form.php`:
Your custom `Form` helper will now be invoked in all instances where `$this->form` is called in a template. For more information on the load order of classes, see [the](core/Libraries::locate)
- Rendering elements
Where `menu` is the name of your element file, in this example `app/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()`:
If you need the element template to not have access to existing data passed to the parent template, use the alternate syntax that calls the `View` render method directly:
- More info**
- [View](template/View) - [Renderer](template/view/Renderer) - [File](template/view/adapter/File)