Skip to content

Commit

Permalink
dirname2
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 18, 2024
1 parent c20c3cd commit dffd525
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 28 deletions.
70 changes: 58 additions & 12 deletions application/cs/templates.texy
Original file line number Diff line number Diff line change
Expand Up @@ -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Γ‘vΓ‘t tady:

/--pre
app/
└── Presenters/
β”œβ”€β”€ HomePresenter.php
└── templates/
β”œβ”€β”€ <b>@layout.latte</b> ← společnΓ½ layout
β”œβ”€β”€ <b>Home.@layout.latte</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Ε―.
Expand Down
78 changes: 62 additions & 16 deletions application/en/templates.texy
Original file line number Diff line number Diff line change
Expand Up @@ -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 to render; the framework will figure out the path on its own, saving you the trouble of writing it.

- `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 (or 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#Chyba 404 a spol.].

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 together in one directory and templates in a `templates` folder, the layout will be expected here:

The layout is expected in the following files:
/--pre
app/
└── Presenters/
β”œβ”€β”€ HomePresenter.php
└── templates/
β”œβ”€β”€ <b>@layout.latte</b> ← common layout
β”œβ”€β”€ <b>Home.@layout.latte</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
Expand Down

0 comments on commit dffd525

Please sign in to comment.