All Projects → FriendsOfREDAXO → twoeg

FriendsOfREDAXO / twoeg

Licence: MIT license
🐣 Implementiert Twig-Templates für REDAXO

Programming Languages

PHP
23972 projects - #3 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to twoeg

undo
Gelöschte Artikel, Slices und Kategorien wiederherstellen
Stars: ✭ 31 (+34.78%)
Mutual labels:  redaxo, redaxo-addon
theme
Nützliche Verwaltung von Projektdateien (z. B. Assets, Sprachdateien, Funktionen und Klassen) für Frontend und Backend.
Stars: ✭ 46 (+100%)
Mutual labels:  redaxo, redaxo-addon
mediapool exif
Holt beim Upload die EXIF-Daten aus dem Bild und setzt diese als Metadaten in die Datenbank ein.
Stars: ✭ 27 (+17.39%)
Mutual labels:  redaxo, redaxo-addon
navbuilder
Generiert frei definierbare Navigationsbäume mittels Drag & Drop
Stars: ✭ 21 (-8.7%)
Mutual labels:  redaxo, redaxo-addon
seoinspector
Ein SEO Ranking Tool fürs REDAXO Backend
Stars: ✭ 22 (-4.35%)
Mutual labels:  redaxo, redaxo-addon
articlelist
🐣 Filter für Artikellisten
Stars: ✭ 20 (-13.04%)
Mutual labels:  redaxo, redaxo-addon
statistics
Statistik Addon zur Erfassung von Seitenaufrufen. Für das CMS Redaxo.
Stars: ✭ 21 (-8.7%)
Mutual labels:  redaxo, redaxo-addon
markitup
Integriert den MarkItUp-Editor (Markdown und Textile) in REDAXO CMS
Stars: ✭ 46 (+100%)
Mutual labels:  redaxo, redaxo-addon
2factor auth
2-Faktor-Authentifizierung mittels one-time-password (OTP)
Stars: ✭ 20 (-13.04%)
Mutual labels:  redaxo, redaxo-addon
demo addon
Beispiel-Addon für REDAXO 5. Zeigt den Aufbau und Basisfunktionalität von Addons.
Stars: ✭ 46 (+100%)
Mutual labels:  redaxo, redaxo-addon
bootstrap helper
Bootstrap Helper für REDAXO 5
Stars: ✭ 22 (-4.35%)
Mutual labels:  redaxo, redaxo-addon
drupal-template-helper
Debug Drupal 8 templates in Chrome Devtools. drupal-template-helper is a chrome extension for Drupal that lists all available templates and the preprocess hooks to use to customize your templates.
Stars: ✭ 115 (+400%)
Mutual labels:  twig, templates
poll
Erstellt und verwaltet Umfragen in REDAXO 5, bei Bedarf mit E-Mailbestätigung.
Stars: ✭ 32 (+39.13%)
Mutual labels:  redaxo, redaxo-addon
yform standalone validator
YForm-Erweiterung: Validieren von PHP Arrays ohne HTML-Formular
Stars: ✭ 23 (+0%)
Mutual labels:  redaxo, redaxo-addon
webdav
🐣 webdav addon to publish mediapool contents
Stars: ✭ 32 (+39.13%)
Mutual labels:  redaxo, redaxo-addon
media srcset
Media-SrcSet implementiert SRCSET-Funktionalität.
Stars: ✭ 36 (+56.52%)
Mutual labels:  redaxo, redaxo-addon
yform usability
Ergänzt YForm um nützliche Funktionen wie Drag & Drop und Status On/Off.
Stars: ✭ 42 (+82.61%)
Mutual labels:  redaxo, redaxo-addon
media manager plus
Ermöglicht das Gruppieren von Media-Manager-Typen und stellt eine Frontend-API (PictureTag) bereit.
Stars: ✭ 21 (-8.7%)
Mutual labels:  redaxo, redaxo-addon
tinymce4
TinyMCE4-Editor für REDAXO 5
Stars: ✭ 21 (-8.7%)
Mutual labels:  redaxo, redaxo-addon
address
Adressverwaltung inkl. Koordinaten (via Google Maps) im Backend
Stars: ✭ 25 (+8.7%)
Mutual labels:  redaxo, redaxo-addon

twÖg AddOn

This redaxo addon adds Twig template engine support for Redaxo 5.

Basic usage

Set up Twig by instance

<?php
    // set up a new Twoeg instance
    $twoeg = new Twoeg();

    // you can use any Twig_Environment method on this class now -
    // for example disable cache:
    $twoeg->setCache(false);

    // load template 'index.html' from default templates folder
    $template = $twoeg->loadTemplate('index.html');

    // render the template and submit variables to be placed in the template:
    echo $template->render([
        'headline' => 'Some headline!',
        'text' => 'translate:twoeg_title'
    ]);
?>

Call it statically too:

<?php

    // we use twÖg with default caching and template folder
    echo Twoeg::render('index.html', ['headline' => 'some static headline', 'text' => 'translate:twoeg_title']);

    // or even simpler without the echo command:
    Twoeg::out('index.html', ['headline' => 'some static headline', 'text' => 'translate:twoeg_title']);
?>

Use rex_i18n::translate or rex_i18n::msg

<html>
    <body>
        <p>{{ 'translate:twoeg_title'|translate }}</p>
        <!-- outputs "twÖg - Twig template engine for Redaxo" //-->

        <p>{{ 'twoeg_title'|msg }}</p>
        <!-- outputs "twÖg - Twig template engine for Redaxo" //-->

        <p>{{ 'twoeg_test'|msg('some', 'variable') }}</p>
        <!-- outputs "twÖg - with »some« of »variable«" //-->

    </body>
</html>

Use any class methods of Redaxo

Use rex::getServerName(), rex_clang::getAll() etc. functions in the template, but instead of using two colons use two underscores - e.g. rex::getServerName() becomes rex__getServerName():

<html>
    <body>
        <p>
            Server name: {{ rex__getServerName() }}
        </p>
        <!-- outputs "Server name: MY_SERVER_NAME" //-->

        <ul>
        {% for item in rex_clang__getAll() %}
            <li>
                {{ item.id }}: {{ item.code }} ({{ item.name}})
            </li>
        {% endfor %}
        </ul>

        <!-- outputs "1: de (deutsch)" //-->

    </body>
</html>

Or even more complex:

Use rex::getUser()->hasRole('admin') or rex::getUser()->getValue('login') in your templates by combining a function and a filter:

<html>
    <body>
        {% if rex__getUser()|hasRole('admin') %}
        <p>
            User login name: {{ rex__getUser()|getValue('login') }}
        </p>
        {% endif %}
    </body>
</html>

Setting template folder

By default, twÖg searches for templates in

redaxo/data/addons/twoeg/template

To change that folder globally you can edit the package.yml in the twoeg addon folder and add

template_folder: 'whatever/path/you/like'

It's also possible to change the template folder when you set up the twÖg instance:

<?php
    // set up a new Twoeg instance
    $twoeg = new Twoeg([
        'template_folder' => 'whatever/path/you/like'
    ]);

    // or statically
    Twoeg::out(
        'index.html', // the template
        ['headline' => 'some static headline', 'text' => 'translate:twoeg_title'], // the variables
        ['template_folder' => 'whatever/path/you/like'] // the options
    );
?>

Caching templates

By default, twÖg will cache the loaded templates into this cache folder:

redaxo/data/addons/twoeg/cache

To change that folder globally you can edit the package.yml in the twoeg addon folder and add

cache_folder: 'whatever/path/you/like'

It's also possible to change the cache folder when you set up the twÖg instance:

<?php
    // set up a new Twoeg instance
    $twoeg = new Twoeg([
        'cache_folder' => 'whatever/path/you/like'
    ]);

    // or statically
    Twoeg::out(
        'index.html', // the template
        ['headline' => 'some static headline', 'text' => 'translate:twoeg_title'], // the variables
        ['cache_folder' => 'whatever/path/you/like'] // the options
    );
?>

To disable caching you have to set the folder to FALSE

<?php
    // set up a new Twoeg instance
    $twoeg = new Twoeg([
        'cache_folder' => false
    ]);

    // or statically
    Twoeg::out(
        'index.html',
        ['headline' => 'some static headline', 'text' => 'translate:twoeg_title'],
        ['cache_folder' => false]
    );
?>

or you can use the Twig_Environment::setCache method through twÖg:

<?php
    $twoeg = new Twoeg();
    $twoeg->setCache(false);
?>    

Filters

By default, twÖg will use these filters

/* translate : */   {{ 'rex_i18n_string_to_translate'|translate }}

/* msg : */         {{ 'rex_i18n_string_to_translate'|msg('some', 'variables') }}

/* get* : */        {{ SOMEOBJECT|getValue('login') }}

/* has* : */        {{ SOMEOBJECT|hasRole('admin') }}

You can add your own filters by providing a "twig_filter" variable when you set up twÖg:

<?php
    // set up a new Twoeg instance
    $twoeg = new Twoeg([
        'twig_filter' => new \Twig_SimpleFilter('myfilter', function ($string) { return strtolower($string); })
    ]);

    // or statically
    Twoeg::out(
        'index.html',
        ['headline' => 'some static headline', 'text' => 'translate:twoeg_title'],
        ['twig_filter' => new \Twig_SimpleFilter('myfilter', function ($string) { return strtolower($string); })]
    );
?>  

Functions

By default, twÖg will try to use any public method of any rex* class that is currently set up, but make sure you replace the two colons by a double underscore:

{{ rex_clang__getCurrentId() }}

{% for item in rex_clang__getAll() %}{{ item.id }}{% endfor %}

// etc.

You can then add a get* or has* filter to the returned value:

{{ rex__getUser()|getValue('login') }}

You can add your own functions by providing a "twig_function" variable when you set up twÖg:

<?php
    // set up a new Twoeg instance
    $twoeg = new Twoeg([
        'twig_function' => new \Twig_SimpleFunction('myfunction', function () { return 'Hello world'; })
    ]);

    // or statically
    Twoeg::out(
        'index.html',
        ['headline' => 'some static headline', 'text' => 'translate:twoeg_title'],
        ['twig_function' => new \Twig_SimpleFunction('myfunction', function () { return 'Hello world'; })]
    );
?>

Twig Extension

You can use any Twig Extension provided by Twig by simply setting a twig_extension variable when you set up twÖg:

<?php
    // set up a new Twoeg instance
    $twoeg = new Twoeg([
        'twig_extension' => ['intl', date']
    ]);

    // or statically
    Twoeg::out(
        'index.html',
        ['headline' => 'some static headline', 'text' => 'translate:twoeg_title'],
        ['twig_extension' => ['intl', date']]
    );
?>

These extensions are available: Array, Date, I18n, Intl, Text.


Credits

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].