vierbergenlars / appendr
This package is abandoned and no longer maintained.
No replacement package was suggested.
v1.2.0
2013-08-17 14:58 UTC
Requires (Dev)
- twig/twig: ~1.13
- vierbergenlars/simpletest: *
This package is not auto-updated.
Last update: 2022-02-01 12:26:18 UTC
README
Appendr is a small plugin to allow template strings to be changed in child templates.
Installation
$ composer require vierbergenlars/appendr:*
Register the extension with your Twig environment
<?php // ... $twig = new Twig_Environment($loader); $twig->addFunction(new \Twig_SimpleFunction('headTitle', new \vierbergenlars\Appendr)); // headTitle is just an example name, you can name it anything you want.
Example
<!DOCTYPE html> <html> <head> <title>{{ headTitle('Website Name') }}</title> {% do headTitle().setSeparator('~') %} {% do headTitle().setDefaultAttachOrder('APPEND') %} </head> <body> {# ... #} </body> </html>
{% extends 'base.twig' %} {% do headTitle('Page name', 'PREPEND') %}
API
All methods are chainable (except the getters).
Assuming headTitle
is an instance of appendr.
headTitle().append('Title')
(Same asheadTitle('Title', 'APPEND')
)headTitle().prepend('Title')
(Same asheadTitle('Title', 'PREPEND')
)headTitle().set('New Title')
(Same asheadTitle('New Title', 'SET')
)headTitle().getSeparator()
headTitle().setSeparator('~')
headTitle().getDefaultAttachOrder()
headTitle().setDefaultAttachOrder('APPEND')
(Also'PREPEND'
and'SET'
)headTitle().getPattern()
headTitle().setPattern('_/°° %s °°\_')
(printf syntax, the pattern is used for each part that is added)
Default options can be passed when registering the Twig function.
<?php use vierbergenlars\Appendr; // ... $twig = new Twig_Environment($loader); // Set default options in the constructor. (null skips an option) $appendr = new Appendr('~', '_/°° %s °°\_', Appendr::APPEND); // And register the Twig function $twig->addFunction(new \Twig_SimpleFunction('fancyTitle', $appendr)); // Or set them on the instance later $appendr->setSeparator('~'); $appendr->setPattern('_/°° %s °°\_'); $appendr->setDefaultAttachOrder(Appendr::APPEND);