Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
8b8b6e5d
Commit
8b8b6e5d
authored
Jul 03, 2013
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using template engines docs
parent
c92c0089
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
91 deletions
+89
-91
index.md
docs/guide/index.md
+4
-3
template.md
docs/guide/template.md
+85
-2
view_renderers.md
docs/view_renderers.md
+0
-86
No files found.
docs/guide/index.md
View file @
8b8b6e5d
...
@@ -8,6 +8,7 @@ Getting started
...
@@ -8,6 +8,7 @@ Getting started
-
[
Installation
](
installation.md
)
-
[
Installation
](
installation.md
)
-
[
Bootstrap with Yii
](
bootstrap.md
)
-
[
Bootstrap with Yii
](
bootstrap.md
)
-
[
Configuration
](
configuration.md
)
Base concepts
Base concepts
=============
=============
...
@@ -17,8 +18,6 @@ Base concepts
...
@@ -17,8 +18,6 @@ Base concepts
-
[
Model
](
model.md
)
-
[
Model
](
model.md
)
-
[
View
](
view.md
)
-
[
View
](
view.md
)
-
[
Application
](
application.md
)
-
[
Application
](
application.md
)
-
[
Form
](
form.md
)
-
[
Model validation reference
](
validation.md
)
Database
Database
========
========
...
@@ -31,6 +30,8 @@ Database
...
@@ -31,6 +30,8 @@ Database
More
More
====
====
-
[
Form
](
form.md
)
-
[
Model validation reference
](
validation.md
)
-
[
Caching
](
caching.md
)
-
[
Caching
](
caching.md
)
-
[
Internationalization
](
i18n.md
)
-
[
Internationalization
](
i18n.md
)
-
[
Extending Yii
](
extension.md
)
-
[
Extending Yii
](
extension.md
)
...
@@ -40,7 +41,7 @@ More
...
@@ -40,7 +41,7 @@ More
-
[
URL Management
](
url.md
)
-
[
URL Management
](
url.md
)
-
[
Theming
](
theming.md
)
-
[
Theming
](
theming.md
)
-
[
Error Handling
](
error.md
)
-
[
Error Handling
](
error.md
)
-
[
Template
](
template.md
)
-
[
Using template engines
](
template.md
)
-
[
Console Application
](
console.md
)
-
[
Console Application
](
console.md
)
-
[
Security
](
security.md
)
-
[
Security
](
security.md
)
-
[
Performance Tuning
](
performance.md
)
-
[
Performance Tuning
](
performance.md
)
...
...
docs/guide/template.md
View file @
8b8b6e5d
Template
Using template engines
========
======================
By default Yii uses PHP as template language but you can configure it to be able
to render templates with special engines such as Twig or Smarty.
The component responsible for rendering a view is called
`view`
. You can add
a custom template engines as follows:
```
php
array
(
'components'
=>
array
(
'view'
=>
array
(
'class'
=>
'yii\base\View'
,
'renderers'
=>
array
(
'tpl'
=>
array
(
'class'
=>
'yii\renderers\SmartyViewRenderer'
,
),
'twig'
=>
array
(
'class'
=>
'yii\renderers\TwigViewRenderer'
,
'twigPath'
=>
'@app/vendors/Twig'
,
),
// ...
),
),
),
)
```
Note that Smarty and Twig are not bundled with Yii and you have to download and
unpack these yourself and then specify
`twigPath`
and
`smartyPath`
respectively.
Twig
----
In order to use Twig you need to put you templates in files with extension
`.twig`
(or another one if configured differently).
Also you need to specify this extension explicitly when calling
`$this->render()`
or
`$this->renderPartial()`
from your controller:
```
php
echo
$this
->
render
(
'renderer.twig'
,
array
(
'username'
=>
'Alex'
));
```
### Additional functions
Additionally to regular Twig syntax the following is available in Yii:
```
php
<a
href=
"{{ path('blog/view', {'alias' : post.alias}) }}"
>
{{ post.title }}
</a>
```
path function calls
`Html::url()`
internally.
### Additional variables
-
`app`
=
`\Yii::$app`
-
`this`
= current
`View`
object
Smarty
------
In order to use Smarty you need to put you templates in files with extension
`.tpl`
(or another one if configured differently).
Also you need to specify this extension explicitly when calling
`$this->render()`
or
`$this->renderPartial()`
from your controller:
```
php
echo
$this
->
render
(
'renderer.tpl'
,
array
(
'username'
=>
'Alex'
));
```
### Additional functions
Additionally to regular Smarty syntax the following is available in Yii:
```
php
<a
href=
"{path route='blog/view' alias=$post.alias}"
>
{$post.title}
</a>
```
path function calls
`Html::url()`
internally.
### Additional variables
-
`$app`
=
`\Yii::$app`
-
`$this`
= current
`View`
object
docs/view_renderers.md
deleted
100644 → 0
View file @
c92c0089
Yii2 view renderers
===================
By default Yii uses PHP as template language but you can configure it to be able
to render templates with special engines such as Twig or Smarty.
The component responsible for rendering a view is called
`view`
. You can add
a custom template engines as follows:
```
php
array
(
'components'
=>
array
(
'view'
=>
array
(
'class'
=>
'yii\base\View'
,
'renderers'
=>
array
(
'tpl'
=>
array
(
'class'
=>
'yii\renderers\SmartyViewRenderer'
,
),
'twig'
=>
array
(
'class'
=>
'yii\renderers\TwigViewRenderer'
,
'twigPath'
=>
'@app/vendors/Twig'
,
),
// ...
),
),
),
)
```
Note that Smarty and Twig are not bundled with Yii and you have to download and
unpack these yourself and then specify
`twigPath`
and
`smartyPath`
respectively.
Twig
----
In order to use Twig you need to put you templates in files with extension
`.twig`
(or another one if configured differently).
Also you need to specify this extension explicitly when calling
`$this->render()`
or
`$this->renderPartial()`
from your controller:
```
php
echo
$this
->
render
(
'renderer.twig'
,
array
(
'username'
=>
'Alex'
));
```
### Additional functions
Additionally to regular Twig syntax the following is available in Yii:
```
php
<a
href=
"{{ path('blog/view', {'alias' : post.alias}) }}"
>
{{ post.title }}
</a>
```
path function calls
`Html::url()`
internally.
### Additional variables
-
`app`
=
`\Yii::$app`
-
`this`
= current
`View`
object
Smarty
------
In order to use Smarty you need to put you templates in files with extension
`.tpl`
(or another one if configured differently).
Also you need to specify this extension explicitly when calling
`$this->render()`
or
`$this->renderPartial()`
from your controller:
```
php
echo
$this
->
render
(
'renderer.tpl'
,
array
(
'username'
=>
'Alex'
));
```
### Additional functions
Additionally to regular Smarty syntax the following is available in Yii:
```
php
<a
href=
"{path route='blog/view' alias=$post.alias}"
>
{$post.title}
</a>
```
path function calls
`Html::url()`
internally.
### Additional variables
-
`$app`
=
`\Yii::$app`
-
`$this`
= current
`View`
object
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment