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
7f6fc398
Commit
7f6fc398
authored
May 05, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #1799: Added form_begin, form_end to twig extension
parent
539b74d1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
19 deletions
+24
-19
tutorial-template-engines.md
docs/guide/tutorial-template-engines.md
+14
-14
CHANGELOG.md
extensions/twig/CHANGELOG.md
+1
-0
ViewRenderer.php
extensions/twig/ViewRenderer.php
+9
-5
No files found.
docs/guide/tutorial-template-engines.md
View file @
7f6fc398
...
...
@@ -52,26 +52,26 @@ or `$this->renderPartial()` controller calls:
echo
$this
->
render
(
'renderer.twig'
,
[
'username'
=>
'Alex'
]);
```
### Additional syntax
Yii adds some extra syntax constructs additionally to standard Twig ones.
###
{{registerAssetBundle('AppAsset')}} - Registers asset bundle of a given name
### Forms
There are two form helper functions
`form_begin`
and
`form_end`
to make using forms more convenient:
```
{% set form = form_begin({ ... }) %}
{{ form.field(...) }}
{% form.end() %}
{% set form = form_begin({
'id' : 'login-form',
'options' : {'class' : 'form-horizontal'},
}) %}
{{ form.field(model, 'username') | raw }}
{{ form.field(model, 'password').passwordInput() | raw }}
<div class="form-group">
<input type="submit" value="Login" class="btn btn-primary" />
</div>
{{ form_end() }}
```
###
#
Getting URL for a route
### Getting URL for a route
There are two functions you can use for URLs:
...
...
extensions/twig/CHANGELOG.md
View file @
7f6fc398
...
...
@@ -5,6 +5,7 @@ Yii Framework 2 twig extension Change Log
--------------------------
-
Bug #2925: Fixed throwing exception when accessing AR property with null value (samdark)
-
Enh #1799: Added
`form_begin`
,
`form_end`
to twig extension (samdark)
2.0.0-beta April 13, 2014
...
...
extensions/twig/ViewRenderer.php
View file @
7f6fc398
...
...
@@ -11,6 +11,7 @@ use Yii;
use
yii\base\View
;
use
yii\base\ViewRenderer
as
BaseViewRenderer
;
use
yii\helpers\Url
;
use
yii\widgets\ActiveForm
;
/**
* TwigViewRenderer allows you to use Twig templates in views.
...
...
@@ -115,11 +116,6 @@ class ViewRenderer extends BaseViewRenderer
$this
->
setLexerOptions
(
$this
->
lexerOptions
);
}
// $this->addFunctions([
// 'rot13' => 'str_rot13',
// 'jsonEncode' => '\yii\helpers\Json::encode',
// ]);
// Adding global 'void' function (usage: {{void(App.clientScript.registerScriptFile(...))}})
$this
->
twig
->
addFunction
(
'void'
,
new
\Twig_Function_Function
(
function
(
$argument
)
{
}));
...
...
@@ -132,6 +128,14 @@ class ViewRenderer extends BaseViewRenderer
return
Url
::
to
(
array_merge
([
$path
],
$args
),
true
);
}));
$this
->
twig
->
addFunction
(
'form_begin'
,
new
\Twig_Function_Function
(
function
(
$args
=
[])
{
return
ActiveForm
::
begin
(
$args
);
}));
$this
->
twig
->
addFunction
(
'form_end'
,
new
\Twig_Function_Function
(
function
()
{
ActiveForm
::
end
();
}));
$this
->
twig
->
addGlobal
(
'app'
,
\Yii
::
$app
);
}
...
...
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