update template doc
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Simon Vieille 2022-03-01 16:23:15 +01:00
parent d4f82fcf91
commit ae053ed1bd

View file

@ -4,13 +4,23 @@
By default, these variables are given to a CMS view:
* `_node`: the current node (`App\Core\Entity\Site\Node`)
* `_page`: the current page (`App\Core\Entity\Site\Page\Page`)
* `_menu`: the menu of the current node (`App\Core\Entity\Site\Menu`)
* `_navigation`: the current navigation (`App\Core\Entity\Site\Navigation`)
* `_domain`: the current domain
* `_locale`: the current locale
* `_store`: an instance of `App\Core\Site\SiteStore`
* The current node is `_node` and its menu is `_menu`
* The current navigation is `_navigation`
* The current locale is `_locale`
* The CMS store is `_store`
## Navigations and menus
* Retrieve all navigations: `_store.navigations`
* Retrieve a navigation by its code: `_store.navigation('the_code')`
* Retrieve all navigation menus: `_navigation.menus`
* Retrieve a menu by its code: `_navigation.menu('the_code')`
* Retrieve all nodes of a menu: `menu.rootNode.children`
* Retrieve visible nodes of a menu: `menu.rootNode.children({visible: true})`
* Test if a node is the current one: `_store.isActiveNode(node)`
* Test if a node is or contains the current one: `_store.isActiveNode(node, true)`
## Page
@ -21,52 +31,6 @@ You can access a page's blocks this way:
{{ myBlock }}
```
## Menu
### Retrieve all menus
```
{% set menus = _navigation.menus %}
```
### Retrieve a specific menu:
```
{% set menu = _navigation.menu('menu_code') %}
```
### Display a menu
```
{% set menu = _navigation.menu('menu_code') %}
<ul>
{% for item in menu.rootNode.children %}
{% if item.isVisible %}
{% set isActive = _store.isActiveNode(item, true) %}
<li {% if isActive %}class="active"{% endif %}>
{% if not item.disableUrl %}
{% set url = item.hasExternalUrl ? item.url : url(node.routeName, {_domain: domain}) %}
<a href="{{ url }}">{{ item.label }}</a>
{% else %}
{{ item.label }}
{% endif %}
{% set children = node.allChildren %}
<ul>
{% for child in children %}
...
{% endfor %}
</ul>
</li>
{% endif %}
{% endfor %}
</ul>
```
## URL and path
Murph has somes twig functions to manage URLs:
@ -83,6 +47,22 @@ Murph has somes twig functions to manage URLs:
* Generates a URL using a node and catches all exceptions: `{{ safe_node_url(node, options, relative) }}`
* Generates a path using a node and catches all exceptions: `{{ safe_node_path(node, options, relative) }}`
A node may have a disabled URL:
```
{% if not node.disableUrl %}
{% set path = safe_node_path(node) %}
{% set url = safe_node_url(node) %}
{% endif %}
```
When the navigation has several domains, you can specify the domain:
```
{% set path = safe_node_path(node, {_domain: _domain}) %}
{% set url = safe_node_url(node, {_domain: _domain}) %}
```
### Filters
When a content could contains tags (eg: '{{url://my_route}}`), use `murph_url`. This the example below:
@ -102,3 +82,12 @@ Examples:
* `{{ 'Hello, {user.displayName}!'|build_string(myEntity) }}` will output `Hello, John doe!`
In case of an not accessible property, no exception will be thrown.
## File attributes
Attributes are managed from the file manager. They are accessibles with these filters:
| Code | Result |
| ------ | ------ |
| `{{ '<img ... alt="{{fattr://hash/alt}}">'|file_attributes }}` | `<img ... alt="Attribute 'alt' of the file with the given hash">` |
| `{{ 'path/to/file'|file_attribute('alt') }}` | Attribute `alt` of the given file |