#push appends to the slot; the layout outputs everything in push order when it renders #stack.
This is the standard pattern for injecting page-specific <link> and <script> tags from child templates.
Directives
| Directive | Used in | Purpose |
|---|---|---|
#stack('name') | Layout | Outputs all content pushed to this slot, in push order. |
#stack('name', 'fallback') | Layout | Outputs a fallback string if nothing was pushed. |
#push('name') … #endpush | Child page / component | Appends a block of content to the named stack. |
Defining stack slots in a layout
Place#stack calls in your layout wherever accumulated content should appear — typically in <head> for stylesheets and before </body> for scripts:
views/layouts/app.lex
Pushing content from a child page
Use#push / #endpush in a child template to inject content into the stack:
views/pages/dashboard.lex
#push('scripts') blocks are appended in order. The rendered <body> closing area will contain:
Stack fallback content
If no template pushes to a stack, pass a second argument to#stack to output a default:
Practical example
The following example shows a layout with both astyles and a scripts stack, and a page that pushes to each.
- Layout
- Child page
- Rendered output
views/layouts/app.lex
Pushing from components
Components can also push to stacks. The pushed content is available in the parent layout, no matter how deeply nested the component is:views/components/chart.lex
Multiple components of the same type each push their own block — all of them are output. If you push the same
<script> tag several times, it will appear multiple times in the output. Deduplicate by managing which components appear on a page, or push only once from the parent page template.