becklyn / gluggi-bundle
Modular layout preview system, to be used within a symfony app.
Installs: 9 924
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 2
Open Issues: 13
Type:symfony-bundle
Requires
- php: >=7.4
- ext-json: *
- becklyn/assets-bundle: ^2.7.1
- symfony/dependency-injection: ^5.4.3 || ^6.0.3
- symfony/finder: ^5.4.3 || ^6.0.3
- symfony/form: ^5.4.3 || ^6.0.3
- symfony/framework-bundle: ^5.4.4 || ^6.0.4
- symfony/http-kernel: ^5.4.4 || ^6.0.4
- symfony/translation: ^5.4.3 || ^6.0.3
- symfony/twig-bundle: ^5.4.3 || ^6.0.3
- symfony/yaml: ^5.4.3 || ^6.0.3
- twig/twig: ^3.3.1
Requires (Dev)
- becklyn/rad: ^8.6.0
- roave/security-advisories: dev-master
- symfony/browser-kit: ^5.4.3 || ^6.0.3
- symfony/css-selector: ^5.4.3 || ^6.0.3
- symfony/phpunit-bridge: ^5.4.3 || ^6.0.3
- symfony/twig-bundle: ^5.4.3 || ^6.0.3
- symfony/var-dumper: ^5.4.3 || ^6.0.3
Suggests
- becklyn/rad: To use the 'form' dummy content.
- becklyn/rad-bundle: To use the 'form' dummy content for projects that haven't upgraded to `becklyn/rad` yet.
- 3.x-dev
- 3.5.0
- 3.4.1
- 3.4.0
- 3.3.0
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.0
- 3.0.0-beta.1
- 2.2.0
- 2.1.0
- 2.0.0
- 1.1.0
- 1.0.1
- 1.0.0
- dev-legacy_support
- dev-dependabot/npm_and_yarn/shell-quote-1.7.3
- dev-dependabot/npm_and_yarn/tar-2.2.2
- dev-dependabot/npm_and_yarn/ini-1.3.8
- dev-dependabot/npm_and_yarn/qs-6.2.4
- dev-dependabot/npm_and_yarn/is-my-json-valid-2.20.6
- dev-dependabot/npm_and_yarn/hosted-git-info-2.8.9
- dev-dependabot/npm_and_yarn/y18n-3.2.2
- dev-dependabot/npm_and_yarn/elliptic-6.5.4
- dev-dependabot/npm_and_yarn/js-yaml-3.13.1
- dev-dependabot/npm_and_yarn/fstream-1.0.12
- dev-dependabot/npm_and_yarn/sshpk-1.16.1
- dev-dependabot/npm_and_yarn/stringstream-0.0.6
This package is auto-updated.
Last update: 2024-11-12 20:24:19 UTC
README
Modular layout system
Installation
-
First install the bundle via composer:
composer require becklyn/gluggi-bundle
-
Load the bundle in your
AppKernel
-
Load the routing in your
routing.yaml
orrouting_dev.yaml
:layout: resource: "@GluggiBundle/Resources/config/routes.yaml" prefix: /_layout/
Configuration
You can define several config values in your app/config.yaml
:
Default configuration
gluggi: layout_dir: _layout info_action: ~ title: ~ data: [] css: [] js: [] js_head: []
Usage
Create a LayoutBundle
and load it in your AppKernel
.
You can add your views in LayoutBundle/Resources/views/{atom,molecule,organism,template,page}
.
Including views in other views
Especially in views that include other subviews it is preferable to just import these subviews, instead of copy & pasting them through the layout project.
Gluggi contains a simple twig function that includes a component:
<div class="wrapper"> {{ gluggi("atom", "example") }} </div>
The function has three parameters: gluggi(type, name [, templateContext])
To keep your templates as minimal and clean as possible, you should always use
{{ gluggi() }}
instead of the twig-own{{ include () }}
and{% include "..." %}
.
Embedding other views
You can also embed other components in the current component, to extend and change some block contents. Use the gluggi_template(type, name)
in the embed
tag.
{% embed gluggi_template("atom", "example") with {a: 1, b: 2} %} {% block some_block %} More content. {% endblock %} {% endembed %}
The function has two parameters: gluggi_template(type, name)
Template variables
Components can use variables (just like any other Twig template).
All templates need to work standalone, so the value of the variable must be defined in the template via {% set variable = ... %}
.
To allow overwriting certain values, the |default(...)
filter from Twig can be used. If the component is included in another template, the variables can be changed.
atom/list.html.twig
:
<ul> {% for i in 1 .. entries|default(3) %} <li>Entry #{{ i }}</li> {% endfor %} </ul>
molecule/long-list.html.twig
:
<div class="long-list"> {{ gluggi("atom", "list", {entries: 10}) }} </div>
Predefined template variables
This is list of predefined variables:
You can overwrite predefined values in included templates, by passing an explicit value as template parameter:
{{ gluggi("atom", "example", {standalone: true}) }}
standalone
The purpose of this variable is to provide an indicator whether the component is previewed in isolation or embedded in another template. This is for example important if a component receives its actual width from the parent.
atom/example.html.twig
:
{% if standalone %}<div style="width: 800px;">{% endif %} <div class="example"> {# ... #} </div> {% if standalone %}</div>{% endif %}
molecule/product.html.twig
:
{# here the width is defined on the product, so the helper <div> shouldn't be in the output #} <div class="product"> {{ gluggi("atom", "example") }} {# includes with standalone = false by default #} </div>
Using assets in views
Referenced assets
Place your images under Resources/public/img
(just as in any other Symfony bundle) and reference the image in your SCSS file via url("../img/...")
.
Inline assets
Load the assets directly from the bundle via becklyn/asset-bundle
's asset()
function:
<!-- Resources/views/atom/example.html.twig --> <div class="example"> <img src="{{ asset("@app/img/example.jpg") }}" alt="Example Image"> </div>
Separating content and layout assets
In a regular layout project, there are some assets that are required for the layout to function (like logos, background images, etc...). And there are content images, that act as placeholders in the layout previews.
It is recommended to separate the two images into two directories:
Resources/public/img
for layout assetsResources/public/content
for content placeholder assets
Styling helpers
There is a styling helper for usage in your layout views. It adds a top margin on every direct child element, except the first child. Use it like this:
<div class="gluggi-variations"> <!-- First component --> <!-- Second component --> <!-- ... --> </div>
If the component itself should not get a top margin, wrap the components in a single div:
<div class="gluggi-variations"> <div><!-- First component --></div> <div><!-- Second component --></div> <!-- ... --> </div>
Template Configuration
You can define configuration parameters in the template, for example setting the body class for a page
component.
Template configuration is defined with a twig comment as the first element in the template:
{#- # the indention is automatically removed some_configuration: test another_value: a -#}
The configuration format is YAML. All configuration parameters are optional.
Defined configuration parameters
Define configuration parameters "add_assets" and "override_assets"
The configuration parameters add_assets
and override_assets
are defined similar to the default configuration.
override_assets: css: [] js: [] js_head: [] add_assets: css: [] js: [] js_head: []
Index Info
The main app can embed arbitrary HTML into the index page. This will be added on the right side, next to the list of components. Just define a controller action in the configuration, and the returned HTML is embedded in the page. If the returned HTML is empty, the info container will be hidden.
gluggi: info_action: "SomeBundle:Test:gluggiInfo"
This will call SomeBundle\Controller\TestController::gluggiInfo()
. This configuration option uses {{ render(controller("...")) }}
internally, so every syntax that is accepted by this call, will be accepted by Gluggi as well.
Template Data
You can define global data, that is accessible in all component templates.
gluggi: data: key1: abc key2: 123 icons: - "add" - "remove" - "search"
This data can be accessed in the templates via {{ gluggi_data(key) }}
.
So for example:
{% for icon in gluggi_data("icons") %} <i class="icon icon-{{ icon }}"></i> {% endfor %}
To ease fast debugging, the twig function will throw an exception, if the key is not defined in the data array.
Dummy Content
To easily produce some example pages, there are several helper functions that render to dummy content:
content
Renders example rich text content.
Options:
headlines
: the number of headline levels to render (default:4
)
form
Renders a form with a lot of different form field types + states.