Using Alternative Template Syntax
=================================
Yii allows developers to use their own favorite template syntax (e.g.
Prado, Smarty) to write controller or widget views. This is achieved by
writing and installing a [viewRenderer|CWebApplication::viewRenderer]
application component. The view renderer intercepts the invocations of
[CBaseController::renderFile], compiles the view file with customized
template syntax, and renders the compiling results.
> Info: It is recommended to use customized template syntax only when
writing views that are less likely to be reused. Otherwise, people who are
reusing the views would be forced to use the same customized template
syntax in their applications.
In the following, we introduce how to use [CPradoViewRenderer], a view
renderer that allows developers to use the template syntax similar to that
in [Prado framework](http://www.pradosoft.com/). For people who want to
develop their own view renderers, [CPradoViewRenderer] is a good reference.
Using `CPradoViewRenderer`
--------------------------
To use [CPradoViewRenderer], we just need to configure the application as
follows:
~~~
[php]
return array(
'components'=>array(
......,
'viewRenderer'=>array(
'class'=>'CPradoViewRenderer',
),
),
);
~~~
By default, [CPradoViewRenderer] will compile source view files and save
the resulting PHP files under the
[runtime](/doc/guide/basics.convention#directory) directory. Only when the
source view files are changed, will the PHP files be re-generated.
Therefore, using [CPradoViewRenderer] incurs very little performance
degradation.
> Tip: While [CPradoViewRenderer] mainly introduces some new template tags
to make writing views easier and faster, you can still write PHP code as
usual in the source views.
In the following, we introduce the template tags that are supported by
[CPradoViewRenderer].
### Short PHP Tags
Short PHP tags are shortcuts to writing PHP expressions and statements in
a view. The expression tag `<%= expression %>` is translated into
``; while the statement tag `<% statement
%>` to ``. For example,
~~~
[php]
<%= CHtml::textField($name,'value'); %>
<% foreach($models as $model): %>
~~~
is translated into
~~~
[php]
~~~
### Component Tags
Component tags are used to insert a
[widget](/doc/guide/basics.view#widget) in a view. It uses the following
syntax:
~~~
[php]