-
-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
120 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,29 +37,75 @@ Ta definuje blok `content`, kterΓ½ se vloΕΎΓ na mΓsto `{include content}` v la | |
HledΓ‘nΓ Ε‘ablon | ||
-------------- | ||
|
||
Cestu k Ε‘ablonΓ‘m odvodΓ presenter podle jednoduchΓ© logiky. ZkusΓ, zda existuje jeden z tΔchto souborΕ― umΓstΔnΓ½ch relativnΔ od adresΓ‘Εe s tΕΓdou presenteru, kde `<Presenter>` je nΓ‘zev aktuΓ‘lnΓho presenteru a `<view>` je nΓ‘zev aktuΓ‘lnΓ akce: | ||
NemusΓte v presenterech uvΓ‘dΔt, jakΓ‘ Ε‘ablona se mΓ‘ vykreslit, framework cestu odvodΓ sΓ‘m a uΕ‘etΕΓ vΓ‘m psanΓ. | ||
|
||
- `templates/<Presenter>/<view>.latte` | ||
- `templates/<Presenter>.<view>.latte` | ||
Pokud pouΕΎΓvΓ‘te adresΓ‘Εovou strukturu, kde kaΕΎdΓ½ presenter mΓ‘ vlastnΓ adresΓ‘Ε, jednoduΕ‘Ε‘e umΓstΔte Ε‘ablonu do tohoto adresΓ‘Εe pod jmΓ©nem akce (resp. view), tj. pro akci `default` pouΕΎijte Ε‘ablonu `default.latte`: | ||
|
||
Pokud Ε‘ablonu nenajde, zkusΓ hledat jeΕ‘tΔ v adresΓ‘Εi `templates` o ΓΊroveΕ vΓ½Ε‘, tj. na stejnΓ© ΓΊrovni, jako je adresΓ‘Ε s tΕΓdou presenteru. | ||
/--pre | ||
app/ | ||
βββ UI/ | ||
βββ Home/ | ||
βββ HomePresenter.php | ||
βββ <b>default.latte</b> | ||
\-- | ||
|
||
Pokud ani tam Ε‘ablonu nenajde, je odpovΔdΓ [chyba 404|presenters#Chyba 404 a spol.]. | ||
Pokud pouΕΎΓvΓ‘te strukturu, kde jsou spoleΔnΔ presentery v jednom adresΓ‘Εi a Ε‘ablony ve sloΕΎce `templates`, uloΕΎte ji buΔ do souboru `<Presenter>.<view>.latte` nebo `<Presenter>/<view>.latte`: | ||
|
||
MΕ―ΕΎete takΓ© zmΔnit view pomocΓ `$this->setView('jineView')`. Nebo mΓsto dohledΓ‘vΓ‘nΓ pΕΓmo urΔit jmΓ©no souboru se Ε‘ablonou pomocΓ `$this->template->setFile('/path/to/template.latte')`. | ||
/--pre | ||
app/ | ||
βββ Presenters/ | ||
βββ HomePresenter.php | ||
βββ templates/ | ||
βββ <b>Home.default.latte</b> β 1. varianta | ||
βββ <b>Home/</b> | ||
βββ <b>default.latte</b> β 2. varianta | ||
\-- | ||
|
||
AdresΓ‘Ε `templates` mΕ―ΕΎe bΓ½t umΓstΔn takΓ© o ΓΊroveΕ vΓ½Ε‘, tj. na stejnΓ© ΓΊrovni, jako je adresΓ‘Ε s tΕΓdami presenterΕ―. | ||
|
||
Pokud se Ε‘ablona nenajde, presenter odpovΓ [chybou 404 - page not found|presenters#Chyba 404 a spol]. | ||
|
||
View zmΔnΓte pomocΓ `$this->setView('jineView')`. TakΓ© lze pΕΓmo urΔit soubor se Ε‘ablonou pomocΓ `$this->template->setFile('/path/to/template.latte')`. | ||
|
||
.[note] | ||
Soubory, kde se dohledΓ‘vajΓ Ε‘ablony, lze zmΔnit pΕekrytΓm metody [formatTemplateFiles() |api:Nette\Application\UI\Presenter::formatTemplateFiles()], kterΓ‘ vracΓ pole moΕΎnΓ½ch nΓ‘zvΕ― souborΕ―. | ||
|
||
Layout se oΔekΓ‘vΓ‘ v tΔchto souborech: | ||
|
||
- `templates/<Presenter>/@<layout>.latte` | ||
- `templates/<Presenter>.@<layout>.latte` | ||
- `templates/@<layout>.latte` layout spoleΔnΓ½ pro vΓce presenterΕ― | ||
HledΓ‘nΓ Ε‘ablony layoutu | ||
----------------------- | ||
|
||
Nette takΓ© automaticky dohledΓ‘vΓ‘ soubor s layoutem. | ||
|
||
Pokud pouΕΎΓvΓ‘te adresΓ‘Εovou strukturu, kde kaΕΎdΓ½ presenter mΓ‘ vlastnΓ adresΓ‘Ε, umΓstΔte layout buΔ do sloΕΎky s presenterem, pokud je specifickΓ½ jen pro nΔj, nebo o ΓΊroveΕ vΓ½Ε‘, pokud je spoleΔnΓ½ pro vΓce presenterΕ―: | ||
|
||
/--pre | ||
app/ | ||
βββ UI/ | ||
βββ <b>@layout.latte</b> β spoleΔnΓ½ layout | ||
βββ Home/ | ||
βββ <b>@layout.latte</b> β jen pro presenter Home | ||
βββ HomePresenter.php | ||
βββ default.latte | ||
\-- | ||
|
||
Pokud pouΕΎΓvΓ‘te strukturu, kde jsou spoleΔnΔ presentery v jednom adresΓ‘Εi a Ε‘ablony ve sloΕΎce `templates`, bude se layout oΔekΓ‘vat na tΔchto mΓstech: | ||
|
||
/--pre | ||
app/ | ||
βββ Presenters/ | ||
βββ HomePresenter.php | ||
βββ templates/ | ||
βββ <b>@layout.latte</b> β spoleΔnΓ½ layout | ||
βββ <b>[email protected]</b> β jen pro Home, 1. varianta | ||
βββ <b>Home/</b> | ||
βββ <b>@layout.latte</b> β jen pro Home, 2. varianta | ||
\-- | ||
|
||
Pokud se presenter nachΓ‘zΓ v [modulu|modules], bude se dohledΓ‘vat i o dalΕ‘Γ adresΓ‘ΕovΓ© ΓΊrovnΔ vΓ½Ε‘, podle zanoΕenΓ modulu. | ||
|
||
Kde `<Presenter>` je nΓ‘zev aktuΓ‘lnΓho presenteru a `<layout>` je nΓ‘zev layoutu, coΕΎ je standardnΔ `'layout'`. NΓ‘zev lze zmΔnit pomocΓ `$this->setLayout('jinyLayout')`, takΕΎe se budou zkouΕ‘et soubory `@jinyLayout.latte`. | ||
NΓ‘zev layoutu lze zmΔnit pomocΓ `$this->setLayout('layoutAdmin')` a pak se bude oΔekΓ‘vat v souboru `@layoutAdmin.latte`. TakΓ© lze pΕΓmo urΔit soubor se Ε‘ablonou layoutu pomocΓ `$this->setLayout('/path/to/template.latte')`. | ||
|
||
MΕ―ΕΎete takΓ© pΕΓmo urΔit jmΓ©no souboru se Ε‘ablonou layoutu pomocΓ `$this->setLayout('/path/to/template.latte')`. PomocΓ `$this->setLayout(false)` se dohledΓ‘vΓ‘nΓ layoutu vypne. | ||
PomocΓ `$this->setLayout(false)` nebo znaΔky `{layout none}` uvnitΕ Ε‘ablony se dohledΓ‘vΓ‘nΓ layoutu vypne. | ||
|
||
.[note] | ||
Soubory, kde se dohledΓ‘vajΓ Ε‘ablony layoutu, lze zmΔnit pΕekrytΓm metody [formatLayoutTemplateFiles() |api:Nette\Application\UI\Presenter::formatLayoutTemplateFiles()], kterΓ‘ vracΓ pole moΕΎnΓ½ch nΓ‘zvΕ― souborΕ―. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,35 +34,81 @@ And this might be the action template: | |
It defines block `content`, which is inserted in place of `{include content}` in the layout, and also re-defines block `title`, which overwrites `{block title}` in the layout. Try to imagine the result. | ||
|
||
|
||
Search for Templates | ||
-------------------- | ||
Template Lookup | ||
--------------- | ||
|
||
The path to the templates is deduced according to simple logic. It tries to see if one of these template files exists relative to the directory where presenter class is located, where `<Presenter>` is the name of the current presenter and `<view>` is the name of the current action: | ||
In presenters, you don't need to specify which template should be rendered; the framework will automatically determine the path, making coding easier for you. | ||
|
||
- `templates/<Presenter>/<view>.latte` | ||
- `templates/<Presenter>.<view>.latte` | ||
If you use a directory structure where each presenter has its own directory, simply place the template in this directory under the name of the action (i.e. view). For example, for the `default` action, use the `default.latte` template: | ||
|
||
If the template is not found, it will try to search in the `templates` directory one level up, i.e., at the same level as the directory with the presenter class. | ||
/--pre | ||
app/ | ||
βββ UI/ | ||
βββ Home/ | ||
βββ HomePresenter.php | ||
βββ <b>default.latte</b> | ||
\-- | ||
|
||
If the template is not found there either, the response is a [404 error|presenters#Error 404 etc.]. | ||
If you use a structure where presenters are together in one directory and templates in a `templates` folder, save it either in a file `<Presenter>.<view>.latte` or `<Presenter>/<view>.latte`: | ||
|
||
You can also change the view using `$this->setView('otherView')`. Or, instead of searching, directly specify the name of the template file using `$this->template->setFile('/path/to/template.latte')`. | ||
/--pre | ||
app/ | ||
βββ Presenters/ | ||
βββ HomePresenter.php | ||
βββ templates/ | ||
βββ <b>Home.default.latte</b> β 1st variant | ||
βββ <b>Home/</b> | ||
βββ <b>default.latte</b> β 2nd variant | ||
\-- | ||
|
||
The `templates` directory can also be placed one level higher, at the same level as the directory with presenter classes. | ||
|
||
If the template is not found, the presenter responds with [404 - page not found error|presenters#Error 404 etc]. | ||
|
||
You can change the view using `$this->setView('anotherView')`. It is also possible to directly specify the template file with `$this->template->setFile('/path/to/template.latte')`. | ||
|
||
.[note] | ||
You can change the paths where templates are searched by overriding the [formatTemplateFiles |api:Nette\Application\UI\Presenter::formatTemplateFiles()] method, which returns an array of possible file paths. | ||
Files where templates are searched can be changed by overriding the method [formatTemplateFiles() |api:Nette\Application\UI\Presenter::formatTemplateFiles()], which returns an array of possible file names. | ||
|
||
|
||
Layout Template Lookup | ||
---------------------- | ||
|
||
Nette also automatically searches for the layout file. | ||
|
||
If you use a directory structure where each presenter has its own directory, place the layout either in the folder with the presenter, if it is specific only to them, or a level higher if it is common to multiple presenters: | ||
|
||
/--pre | ||
app/ | ||
βββ UI/ | ||
βββ <b>@layout.latte</b> β common layout | ||
βββ Home/ | ||
βββ <b>@layout.latte</b> β only for Home presenter | ||
βββ HomePresenter.php | ||
βββ default.latte | ||
\-- | ||
|
||
If you use a structure where presenters are grouped together in one directory and templates are in a `templates` folder, the layout will be expected in the following places: | ||
|
||
The layout is expected in the following files: | ||
/--pre | ||
app/ | ||
βββ Presenters/ | ||
βββ HomePresenter.php | ||
βββ templates/ | ||
βββ <b>@layout.latte</b> β common layout | ||
βββ <b>[email protected]</b> β only for Home, 1st variant | ||
βββ <b>Home/</b> | ||
βββ <b>@layout.latte</b> β only for Home, 2nd variant | ||
\-- | ||
|
||
- `templates/<Presenter>/@<layout>.latte` | ||
- `templates/<Presenter>.@<layout>.latte` | ||
- `templates/@<layout>.latte` layout common to multiple presenters | ||
If the presenter is in a [module|modules], it will also search further up the directory tree according to the module's nesting. | ||
|
||
`<Presenter>` is the name of the current presenter and `<layout>` is the name of the layout, which is by default `'layout'`. The name can be changed with `$this->setLayout('otherLayout')`, so that `@otherLayout.latte` files will be tried. | ||
The name of the layout can be changed using `$this->setLayout('layoutAdmin')` and then it will be expected in the file `@layoutAdmin.latte`. You can also directly specify the layout template file using `$this->setLayout('/path/to/template.latte')`. | ||
|
||
You can also directly specify the file name of the layout template using `$this->setLayout('/path/to/template.latte')`. Using `$this->setLayout(false)` will disable the layout searching. | ||
Using `$this->setLayout(false)` or the `{layout none}` tag inside the template disables layout search. | ||
|
||
.[note] | ||
You can change the paths where templates are searched by overriding the [formatLayoutTemplateFiles |api:Nette\Application\UI\Presenter::formatLayoutTemplateFiles()] method, which returns an array of possible file paths. | ||
Files where layout templates are searched can be changed by overriding the method [formatLayoutTemplateFiles() |api:Nette\Application\UI\Presenter::formatLayoutTemplateFiles()], which returns an array of possible file names. | ||
|
||
|
||
Variables in the Template | ||
|