Twig
Mayd provides Twig integrations for the frontend, as well as the backend of Mayd applications.
Functions
A list of all Twig functions, provided by Mayd. Please refer to their documentation about details of their usage.
file_url()
Provided by mayd/files
, mainly usable in frontend.
Generates a download URL to a file.
{{ file_url(file, true) }}
name | type | default | description |
---|---|---|---|
file | FileEntry|FileData|int|string | The id / entity / VO of the file to generate the link to. | |
embed | bool | false | Whether the download should try to embed the file or always download it. |
type | description |
---|---|
string|null | The URL, or null if the file was not found. |
Embedding a download depends on browser support. Nearly all browser support embedding a PDF for example, that means the file is not downloaded, but instead opened inside the browser tab.
homepage_url()
Provided by mayd/pages
, usable in frontend & backend.
{{ homepage_url(website) }}
name | type | description |
---|---|---|
website | Website | The website to generate the homepage url to. |
type | description |
---|---|
string | The absolute URL to the homepage. |
hyperlink_tag()
Provided by mayd/core
, mainly usable in frontend.
Resolves a hyperlink and renders it as HTML link, if it was able to resolve it. If the URL doesn’t resolve
it will render to a <button>
.
{{ hyperlink_tag(link, "Some link text", {class: "button-link") }}
name | type | default | description |
---|---|---|---|
link | Hyperlink|null | The link to resolve. | |
content | string | The link / button text. | |
attributes | array | [] | Additional HTML attributes for the generated button / link. |
type | description |
---|---|
string|null | The render link / button. null only if the link itself was null . |
hyperlink_url()
Provided by mayd/core
, mainly usable in frontend.
Resolves a hyperlink and returns the URL, if it was able to resolve it.
{{ hyperlink_url(link) }}
name | type | description |
---|---|---|
link | Hyperlink|null | The link to resolve. |
type | description |
---|---|
string|null | The link if was able to resolve it, null otherwise. |
If you are rendering the URL into a link / button, you should always use the hyperlink_tag() function, so that all integrations from the hyperlink system are automatically applied.
image_tag()
Provided by mayd/files
, mainly usable in frontend.
Similar to image_url(), but directly renders an <img>
tag. Can be passed additional parameters.
{{ image_url(image, "content-slider") }}
name | type | default | description |
---|---|---|---|
image | FileEntry|FileData|int|string | The image to get the URL for. | |
size | string | The image size to fetch. | |
attributes | array | [] | Additional HTML attributes to attach to the file. |
language | Language | null | The language to automatically add the alt texts for. If null , the language from MaydView is used. |
type | description |
---|---|
string|null | The HTML for the image tag, or null if the file was not found. |
This function automatically marks all images as loading="lazy"
for performance reasons.
In the future, this function will directly embed the width / height of the image, to improve loading.
image_url()
Provided by mayd/files
, mainly usable in frontend.
Generates a URL to an image, that can be used inside an <img>
tag or as background image URL.
{{ image_url(image, "content-slider") }}
name | type | description |
---|---|---|
image | FileEntry|FileData|int|string | The image to get the URL for. |
size | string | The image size to fetch. |
type | description |
---|---|
string|null | The URL, or null if the file was not found. |
Instead of <img src="{{ image_url() }}">
you should always use image_tag()
.
mayd_crud()
Provided by mayd/crud
, should only be used in the backend.
Embeds a CRUD editor in the backend.
{{ mayd_crud("some.key", "locations.crud.headline", )
name | type | default | description |
---|---|---|---|
key | string | The CRUD manager key | |
headline | string | The headline of the CRUD manager. | |
contextOrData | array|CrudContext | [] | The context of the crud manager |
options | array | [] | Additional options |
options.emptyMessage | string | "..." | The label to show if the result is empty. |
options.addLabel | string | "..." | The label to show for "add a new entry". |
options.headlineTranslationParams | string | [] | Additional translation params to translate the headline. |
options.headlineIsPageTitle | bool | true | Whether the CRUD headline acts as page title. |
options.searchPlaceholder | string | "..." | The input placeholder for the search field |
type | description |
---|---|
string | The HTML embed code, that will automatically be picked up by the JSX CRUD component. |
Some comments about the options:
- If you have a page title before the CRUD manager, you should set
options.headlineIsPageTitle
to false. - Every label / message in the options, as well as the
headline
will automatically be translated in thebackend
domain.
mayd_feature()
Provided by mayd/core
, usable in frontend & backend.
Returns whether a Mayd feature flag is enabled.
{% if mayd_feature("some-feature") %}
name | type | description |
---|---|---|
feature | string | The key of the feature. |
type | description |
---|---|
bool | Whether the feature is enabled. |
All unknown features will always be disabled.
This checks for Mayd feature flags, not project feature flags. Use project_feature() for that.
mayd_form()
Provided by mayd/forms
, mainly usable in frontend.
Renders a Mayd form in the frontend.
{{ mayd_form(context, frontendForm) }}
name | type | default | description |
---|---|---|---|
context | WebsiteRequestContextInterface | The website request context. | |
form | FrontendForm | The frontend form to render | |
additionalData | array | [] | Additional data to add to the form (see the form docs for details about that parameter). |
renderOptions | array | [] | Options for manipulating the rendering. |
renderOptions.formTheme | string | "..." | The form theme to use when rendering the form. |
type | description |
---|---|
string | The rendered HTML form. |
If you need a custom form theme, you should always extend the base @MaydForms/frontend/theme.html.twig
form theme.
mayd_form_themes()
Provided by mayd/core
, should only be used in the backend.
Returns the list of all registered form themes. This includes the form themes by Mayd bundles, as well as the project’s own form theme, set in the Kernel.
{%- form_theme form with mayd_form_themes() -%}
type | description |
---|---|
string[] | The list of all registered form themes. |
You must set this flag in every backend form, to have proper form rendering.
mayd_form_value()
Provided by mayd/forms
, should only be used in the backend.
The Mayd forms component normalizes input values before storing them in the database. This function renders such normalized values.
{{ mayd_form_value(value) }}
name | type | description |
---|---|---|
value | mixed | The value to render. |
type | description |
---|---|
string | The rendered value (as HTML). |
mayd_logout_url()
Provided by mayd/core
, usable in frontend & backend.
Generates the URL to the logout. You can pass an optional relog
key, to directly redirect to the login form
of the frontend authenticator with the same key
.
{{ mayd_logout_url("mayd") }}
name | type | default | description |
---|---|---|---|
relog | string|null | null |
type | description |
---|---|
string | The logout URL. |
mayd_slot_admin()
Provided by mayd/pages
, should only be used in the backend.
Renders the data container to embed a slot admin.
{{ mayd_slot_admin(slot) }}
name | type | description |
---|---|---|
slot | Slot|null | The slot to embed the slot admin for. |
type | description |
---|---|
string | The HTML embed code, that will automatically be picked up by the slot admin JS component. |
mayd_support_enabled()
Provided by mayd/core
, usable in frontend & backend.
Returns whether the user has support mode enabled.
{% if mayd_support_enabled() %}
type | description |
---|---|
bool |
mayd_tab_links()
Provided by mayd/core
, should only be used in the backend.
Renders the links directly under the given parent as tab links.
{{- mayd_tab_links("route.key", {language: language}) -}}
name | type | default | description |
---|---|---|---|
parent | string | The parent route to generate the tab links for. | |
parameters | array | [] | The parameters to resolve the links to. |
routeSpecificParameters | array | [] | Route specific parameters to resolve the links to. |
type | description |
---|---|
string | The rendered tab link navigation (as HTML). |
This function basically renders a small, only one level deep route tree, styled as tab links.
If any of the routes require certain parameters, you can pass these in parameters
as a
key-value mapping (like {language: languageEntity.id}
). If you have name clashes (= the same
parameter name means different things in the different routes), you can override the parameters
for
specific routes in routeSpecificParameters
, by passing the parameters for the given route explicitly.
{{- mayd_tab_links(
"route.key",
{language: language.id},
{
"child.route": {
language: "de",
},
}
) -}}
mayd_toasts_init()
Provided by mayd/core
, usable in frontend & backend.
Initializes the (Symfony-based) toasts for the frontend.
{{ mayd_toasts_init("_app-toasts-data") }}
name | type | description |
---|---|---|
dataContainerClass | string | The HTML class for the data container. |
type | description |
---|---|
string | The rendered data container, that will be picked up by the JS component (as HTML). |
page_url()
Provided by mayd/pages
, usable in frontend & backend.
Returns the absolute path to the given page.
{{ page_url(page, "sub.route", {language: "de"}) }}
name | type | default | description |
---|---|---|---|
page | PageTreeNode|TreeNodeData|null | The page to generate the link to. | |
route | string | "index" | The sub route to generate to. |
routeParameters | array | [] | The route parameters for the sub route. |
type | description |
---|---|
string|null | The absolute path URL to the given page + sub route. |
The page router automatically performs context switches: so it recognizes if the domain is different and will automatically generate an absolute URL, if needed.
page_url_absolute()
Provided by mayd/pages
, mainly usable in frontend.
Returns the absolute URL to the given page.
{{ page_url_absolute(page, "sub.route", {language: "de"}) }}
name | type | default | description |
---|---|---|---|
page | PageTreeNode|TreeNodeData|null | The page to generate the link to. | |
route | string | "index" | The sub route to generate to. |
routeParameters | array | [] | The route parameters for the sub route. |
type | description |
---|---|
string|null | The absolute URL to the given page + sub route. |
project_feature()
Provided by mayd/core
, usable in frontend & backend.
Returns whether a project feature flag is enabled.
{% if project_feature("some-feature") %}
name | type | description |
---|---|---|
feature | string | The key of the feature. |
type | description |
---|---|
bool | Whether the feature is enabled. |
All unknown features will always be disabled.
This checks for project feature flags, not Mayd feature flags. Use mayd_feature() for that.
render_slot()
Provided by mayd/pages
, mainly usable in frontend.
Renders the slot contents for the frontend.
{{ render_slot(slot, requestContext) }}
name | type | description |
---|---|---|
slot | Slot|null | The slot to render. |
context | RequestContextInterface | The request context, to render the slot in. |
type | description |
---|---|
string | The rendered slot contents (as HTML). |
rich_text()
Provided by mayd/rich-text
, mainly usable in frontend.
Renders a rich text for the frontend. Uses the central rich text renderer, to apply some transformations to the HTML.
{{ rich_text(text) }}
name | type | description |
---|---|---|
text | string|null | The text to render. |
type | description |
---|---|
string|null | The rendered text (as HTML). |
If you want to render a plain text and just have proper line breaks, you can use
Twig’s native |nl2br
filter on any variable for that.
Important Blocks
This section lists important blocks, that you can override in your template.
Backend
Block Name | Usage | Description |
---|---|---|
| Global body. | (internal, should not be used) |
| The breadcrumb entries. | Should directly render to |
| The main content. | (empty) |
| The assets in the footer. | Must call |
| Additional (modifier) classes for | (empty) should just return plain string. |
| The assets in the head. | Must call |
| The meta title | You should never override this block directly, but instead use the |
Frontend
Most of the frontend blocks come from your own layout.html.twig
template, but there are some blocks in the base layout.
Your frontend layout.html.twig
should always
{% extends "@MaydCore/frontend.html.twig" %}
The base frontend blocks are:
Block Name | Usage | Description |
---|---|---|
| The assets in the footer. | Must call |
| The assets in the head. | Must call |
| The main content. | (empty) |
| The meta tags | (empty) |
| The meta title | (empty) |
| Any tracking scripts. | Must call |
Globals
Variable Name | Type | Description |
---|---|---|
|
| The global mayd view. |
Global Template Variables
These are variables that you should (or could) pass to your templates. These variables differ between frontend and backend, so they are listed separately.
Backend
Variable Name | Required? | Type | Description |
---|---|---|---|
| no |
| Used for generating |
| no |
| If this variable is available, the corresponding view filter selectors will be rendered. |
| no |
| The meta title instance to display. Normally generated via |
Frontend
Variable Name | Required? | Type | Description |
---|---|---|---|
| no |
| The request context. Technically not required, but should |
Request Context
One very important variable is the request context. It (together with possibly other things) is most
easily passed to the template by just using the mergeParameters()
function from it in your action:
use Mayd\Foundation\Request\Context\PageRequestContextInterface;
public function someAction (PageRequestContextInterface $context) : Response
{
// ...
return $this->render("...", $context->mergeParameters([
// ... more custom parameters
]);
}
- Functions
file_url()
homepage_url()
hyperlink_tag()
hyperlink_url()
image_tag()
image_url()
mayd_crud()
mayd_feature()
mayd_form()
mayd_form_themes()
mayd_form_value()
mayd_logout_url()
mayd_menu()
mayd_menu_tree()
mayd_slot_admin()
mayd_support_enabled()
mayd_tab_links()
mayd_toasts_init()
page_url()
page_url_absolute()
project_feature()
render_slot()
rich_text()
- Important Blocks
- Globals
- Global Template Variables