From ae053ed1bde371ba85591ae58cc7841dbda84896 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Tue, 1 Mar 2022 16:23:15 +0100 Subject: [PATCH] update template doc --- docs/template.md | 95 +++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 53 deletions(-) diff --git a/docs/template.md b/docs/template.md index 656a5cc..e5d56b7 100644 --- a/docs/template.md +++ b/docs/template.md @@ -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') %} - - -``` - ## 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 | +| ------ | ------ | +| `{{ '{{fattr://hash/alt}}'|file_attributes }}` | `Attribute 'alt' of the file with the given hash` | +| `{{ 'path/to/file'|file_attribute('alt') }}` | Attribute `alt` of the given file |