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
6c80cba3
Commit
6c80cba3
authored
Dec 19, 2014
by
larnu
Committed by
Carsten Brandt
Dec 19, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update spanish helper-html.md
close #6578
parent
ee67d164
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
29 deletions
+30
-29
helper-html.md
docs/guide-es/helper-html.md
+6
-6
helper-html.md
docs/guide/helper-html.md
+24
-23
No files found.
docs/guide-es/helper-html.md
View file @
6c80cba3
...
@@ -162,10 +162,10 @@ especifica directamente.
...
@@ -162,10 +162,10 @@ especifica directamente.
Los métodos más genéricos son:
Los métodos más genéricos son:
```
php
```
php
//
type, input name, input value, options
type, input name, input value, options
<?=
Html
::
input
(
'text'
,
'username'
,
$user
->
name
,
[
'class'
=>
$username
])
?>
<?=
Html
::
input
(
'text'
,
'username'
,
$user
->
name
,
[
'class'
=>
$username
])
?>
//
type, model, model attribute name, options
type, model, model attribute name, options
<?=
Html
::
activeInput
(
'text'
,
$user
,
'name'
,
[
'class'
=>
$username
])
?>
<?=
Html
::
activeInput
(
'text'
,
$user
,
'name'
,
[
'class'
=>
$username
])
?>
```
```
...
@@ -282,13 +282,13 @@ Existen dos métodos para generar etiquetas que envuelvan estilos y scripts incr
...
@@ -282,13 +282,13 @@ Existen dos métodos para generar etiquetas que envuelvan estilos y scripts incr
```
php
```
php
<?=
Html
::
style
(
'.danger { color: #f00; }'
)
?>
<?=
Html
::
style
(
'.danger { color: #f00; }'
)
?>
//
Genera
Genera
<style>
.danger
{
color
:
#f00
;
}
</style>
<style>
.danger
{
color
:
#f00
;
}
</style>
<?=
Html
::
script
(
'alert("Hello!");'
,
[
'defer'
=>
true
]);
<?=
Html
::
script
(
'alert("Hello!");'
,
[
'defer'
=>
true
]);
//
Genera
Genera
<
script
defer
>
alert
(
"Hello!"
);
</
script
>
<
script
defer
>
alert
(
"Hello!"
);
</
script
>
```
```
...
@@ -298,7 +298,7 @@ Si se quiere enlazar un estilo externo desde un archivo CSS:
...
@@ -298,7 +298,7 @@ Si se quiere enlazar un estilo externo desde un archivo CSS:
```
php
```
php
<?=
Html
::
cssFile
(
'@web/css/ie5.css'
,
[
'condition'
=>
'IE 5'
])
?>
<?=
Html
::
cssFile
(
'@web/css/ie5.css'
,
[
'condition'
=>
'IE 5'
])
?>
//
genera
genera
<!--[if IE 5]>
<!--[if IE 5]>
<link href="http://example.com/css/ie5.css" />
<link href="http://example.com/css/ie5.css" />
...
@@ -351,7 +351,7 @@ Para generar una etiqueta de tipo imagen se puede usar el siguiente ejemplo:
...
@@ -351,7 +351,7 @@ Para generar una etiqueta de tipo imagen se puede usar el siguiente ejemplo:
```
php
```
php
<?=
Html
::
img
(
'@web/images/logo.png'
,
[
'alt'
=>
'My logo'
])
?>
<?=
Html
::
img
(
'@web/images/logo.png'
,
[
'alt'
=>
'My logo'
])
?>
//
genera
genera
<img
src=
"http://example.com/images/logo.png"
alt=
"My logo"
/>
<img
src=
"http://example.com/images/logo.png"
alt=
"My logo"
/>
```
```
...
...
docs/guide/helper-html.md
View file @
6c80cba3
...
@@ -9,6 +9,7 @@ of Html helper which provides a set of static methods for handling commonly used
...
@@ -9,6 +9,7 @@ of Html helper which provides a set of static methods for handling commonly used
> Note: If your markup is nearly static it's better to use HTML directly. There's no need to wrap absolutely everything
> Note: If your markup is nearly static it's better to use HTML directly. There's no need to wrap absolutely everything
with Html helper calls.
with Html helper calls.
Basics <a name="basics"></a>
Basics <a name="basics"></a>
----------------------------
----------------------------
...
@@ -39,7 +40,7 @@ In case you need just start tag or just closing tag you can use `Html::beginTag(
...
@@ -39,7 +40,7 @@ In case you need just start tag or just closing tag you can use `Html::beginTag(
Options are used in many methods of Html helper and various widgets. In all these cases there is some extra handling to
Options are used in many methods of Html helper and various widgets. In all these cases there is some extra handling to
know about:
know about:
-
If a value is null, the corresponding attribute will not be rendered.
-
If a value is null, the corresponding attribute will not be rendered.
-
Attributes whose values are of boolean type will be treated as
-
Attributes whose values are of boolean type will be treated as
[
boolean attributes
](
http://www.w3.org/TR/html5/infrastructure.html#boolean-attributes
)
.
[
boolean attributes
](
http://www.w3.org/TR/html5/infrastructure.html#boolean-attributes
)
.
...
@@ -49,13 +50,12 @@ know about:
...
@@ -49,13 +50,12 @@ know about:
-
The "data" attribute could receive JSON. It is handled the same way as array i.e.
-
The "data" attribute could receive JSON. It is handled the same way as array i.e.
`'data' => ['params' => ['id' => 1, 'name' => 'yii'], 'status' => 'ok']`
becomes
`'data' => ['params' => ['id' => 1, 'name' => 'yii'], 'status' => 'ok']`
becomes
`data-params='{"id":1,"name":"yii"}' data-status="ok"`
.
`data-params='{"id":1,"name":"yii"}' data-status="ok"`
.
### Forming class and style dynamically
### Forming class and style dynamically
When building options for HTML tag we're often starting with defaults which we need to modify. In order to add or
When building options for HTML tag we're often starting with defaults which we need to modify. In order to add or
remove CSS class you can use the following:
remove CSS class you can use the following:
```
php
```
php
$options
=
[
'class'
=>
'btn btn-default'
];
$options
=
[
'class'
=>
'btn btn-default'
];
...
@@ -88,7 +88,7 @@ could be converted there and forth by using [[yii\helpers\Html::cssStyleFromArra
...
@@ -88,7 +88,7 @@ could be converted there and forth by using [[yii\helpers\Html::cssStyleFromArra
[
[yii\helpers\Html::cssStyleToArray()|cssStyleToArray()
]
]. The
[
[yii\helpers\Html::removeCssStyle()|removeCssStyle()
]
]
[
[yii\helpers\Html::cssStyleToArray()|cssStyleToArray()
]
]. The
[
[yii\helpers\Html::removeCssStyle()|removeCssStyle()
]
]
method accepts an array of properties to remove. If it's going to be a single property it could be specified as string.
method accepts an array of properties to remove. If it's going to be a single property it could be specified as string.
Encoding and decoding content <a name="encoding-and-decoding-content"></a>
Encoding and decoding content <a name="encoding-and-decoding-content"></a>
--------------------------------------------------------------------------
--------------------------------------------------------------------------
...
@@ -104,7 +104,7 @@ $userName = Html::encode($user->name);
...
@@ -104,7 +104,7 @@ $userName = Html::encode($user->name);
echo
$userName
;
echo
$userName
;
$decodedUserName
=
Html
::
decode
(
$userName
);
$decodedUserName
=
Html
::
decode
(
$userName
);
```
```
Forms
Forms
...
@@ -115,6 +115,7 @@ dealing with them.
...
@@ -115,6 +115,7 @@ dealing with them.
> Note: consider using [[yii\widgets\ActiveForm|ActiveForm]] in case you deal with models and need validation.
> Note: consider using [[yii\widgets\ActiveForm|ActiveForm]] in case you deal with models and need validation.
### Open and close a form
### Open and close a form
Form could be opened with
[
[yii\helpers\Html::beginForm()|beginForm()
]
] method like the following:
Form could be opened with
[
[yii\helpers\Html::beginForm()|beginForm()
]
] method like the following:
...
@@ -134,6 +135,7 @@ Closing form tag is simple:
...
@@ -134,6 +135,7 @@ Closing form tag is simple:
<?=
Html
::
endForm
()
?>
<?=
Html
::
endForm
()
?>
```
```
### Buttons
### Buttons
In order to generate buttons you can use the following code:
In order to generate buttons you can use the following code:
...
@@ -154,7 +156,6 @@ There are two groups on input methods. The ones starting with `active` and calle
...
@@ -154,7 +156,6 @@ There are two groups on input methods. The ones starting with `active` and calle
with it. Active inputs are taking data from model and attribute specified while in case of regular input data is specified
with it. Active inputs are taking data from model and attribute specified while in case of regular input data is specified
directly.
directly.
The most generic methods are:
The most generic methods are:
```
php
```
php
...
@@ -198,7 +199,7 @@ Dropdown list and list box could be rendered like the following:
...
@@ -198,7 +199,7 @@ Dropdown list and list box could be rendered like the following:
First argument is the name of the input, second is the value that's currently selected and third is key-value pairs where
First argument is the name of the input, second is the value that's currently selected and third is key-value pairs where
array key is list value and array value is list label.
array key is list value and array value is list label.
If you want multiple choices to be selectable, checkbox list is a good match:
If you want multiple choices to be selectable, checkbox list is a good match:
```
php
```
php
...
@@ -213,9 +214,8 @@ If not, use radio list:
...
@@ -213,9 +214,8 @@ If not, use radio list:
<?=
Html
::
activeRadioList
(
$user
,
'role'
,
ArrayHelper
::
map
(
$roleModels
,
'id'
,
'name'
))
?>
<?=
Html
::
activeRadioList
(
$user
,
'role'
,
ArrayHelper
::
map
(
$roleModels
,
'id'
,
'name'
))
?>
```
```
### Labels and errors
### Labels and errors
Same as inputs there are two methods for generating form labels. Active that's taking data from the model and non-active
Same as inputs there are two methods for generating form labels. Active that's taking data from the model and non-active
that accepts data directly:
that accepts data directly:
...
@@ -224,7 +224,7 @@ that accepts data directly:
...
@@ -224,7 +224,7 @@ that accepts data directly:
<?=
Html
::
label
(
'User name'
,
'username'
,
[
'class'
=>
'label username'
])
?>
<?=
Html
::
label
(
'User name'
,
'username'
,
[
'class'
=>
'label username'
])
?>
<?=
Html
::
activeLabel
(
$user
,
'username'
,
[
'class'
=>
'label username'
])
<?=
Html
::
activeLabel
(
$user
,
'username'
,
[
'class'
=>
'label username'
])
```
```
In order to display form errors from a model or models as a summary you could use:
In order to display form errors from a model or models as a summary you could use:
```
php
```
php
...
@@ -236,10 +236,10 @@ To display individual error:
...
@@ -236,10 +236,10 @@ To display individual error:
```
php
```
php
<?=
Html
::
error
(
$post
,
'title'
,
[
'class'
=>
'error'
])
?>
<?=
Html
::
error
(
$post
,
'title'
,
[
'class'
=>
'error'
])
?>
```
```
### Names and values
### Names and values
There are methods to get names, ids and values for input fields based on the model. These are mainly used internally
There are methods to get names, ids and values for input fields based on the model. These are mainly used internally
but could be handy sometimes:
but could be handy sometimes:
...
@@ -271,14 +271,13 @@ In order to get attribute name without suffixes or prefixes one can use the foll
...
@@ -271,14 +271,13 @@ In order to get attribute name without suffixes or prefixes one can use the foll
// dates
// dates
echo
Html
::
getAttributeName
(
'dates[0]'
);
echo
Html
::
getAttributeName
(
'dates[0]'
);
```
```
Styles and scripts
Styles and scripts
------------------
------------------
There two methods to generate tags wrapping embedded styles and scripts:
There two methods to generate tags wrapping embedded styles and scripts:
```
php
```
php
<?=
Html
::
style
(
'.danger { color: #f00; }'
)
?>
<?=
Html
::
style
(
'.danger { color: #f00; }'
)
?>
...
@@ -321,12 +320,13 @@ To link JavaScript file:
...
@@ -321,12 +320,13 @@ To link JavaScript file:
Same as with CSS first argument specifies link to the file to be included. Options could be passed as the second argument.
Same as with CSS first argument specifies link to the file to be included. Options could be passed as the second argument.
In options you can specify
`condition`
in the same way as in options for
`cssFile`
.
In options you can specify
`condition`
in the same way as in options for
`cssFile`
.
Links
Links
-----
-----
There's a method to generate hyperlink conveniently:
There's a method to generate hyperlink conveniently:
```
php
```
php
<?=
Html
::
a
(
'Profile'
,
[
'user/view'
,
'id'
=>
$id
],
[
'class'
=>
'profile-link'
])
?>
<?=
Html
::
a
(
'Profile'
,
[
'user/view'
,
'id'
=>
$id
],
[
'class'
=>
'profile-link'
])
?>
```
```
...
@@ -336,17 +336,17 @@ The first argument is the title. It's not encoded so if you're using data got fr
...
@@ -336,17 +336,17 @@ The first argument is the title. It's not encoded so if you're using data got fr
what values it accepts. Third argument is array of tag properties.
what values it accepts. Third argument is array of tag properties.
In you need to generate
`mailto`
link you can use the following code:
In you need to generate
`mailto`
link you can use the following code:
```
php
```
php
<?=
Html
::
mailto
(
'Contact us'
,
'admin@example.com'
)
?>
<?=
Html
::
mailto
(
'Contact us'
,
'admin@example.com'
)
?>
```
```
Images
Images
------
------
In order to generate image tag use the following:
In order to generate image tag use the following:
```
php
```
php
<?=
Html
::
img
(
'@web/images/logo.png'
,
[
'alt'
=>
'My logo'
])
?>
<?=
Html
::
img
(
'@web/images/logo.png'
,
[
'alt'
=>
'My logo'
])
?>
...
@@ -357,10 +357,11 @@ generates
...
@@ -357,10 +357,11 @@ generates
Aside
[
aliases
](
concept-aliases.md
)
the first argument can accept routes, parameters and URLs. Same way as
Aside
[
aliases
](
concept-aliases.md
)
the first argument can accept routes, parameters and URLs. Same way as
[
Url::to()
](
helper-url.md
)
does.
[
Url::to()
](
helper-url.md
)
does.
Lists
Lists
-----
-----
Unordered list could be generated like the following:
Unordered list could be generated like the following:
```
php
```
php
...
...
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