2017 © Pedro Peláez
 

library appendr

image

vierbergenlars/appendr

  • Saturday, August 17, 2013
  • by vierbergenlars
  • Repository
  • 1 Watchers
  • 0 Stars
  • 71 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Appendr

Build Status, (*1)

Appendr is a small plugin to allow template strings to be changed in child templates., (*2)

Installation

$ composer require vierbergenlars/appendr:*, (*3)

Register the extension with your Twig environment, (*4)

<?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)., (*5)

Assuming headTitle is an instance of appendr., (*6)

  • headTitle().append('Title') (Same as headTitle('Title', 'APPEND') )
  • headTitle().prepend('Title') (Same as headTitle('Title', 'PREPEND') )
  • headTitle().set('New Title') (Same as headTitle('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., (*7)

<?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);

The Versions

17/08 2013

dev-master

9999999-dev

  Sources   Download

MIT

The Development Requires

by Lars Vierbergen

17/08 2013

v1.2.0

1.2.0.0

  Sources   Download

MIT

The Development Requires

by Lars Vierbergen

17/08 2013

v1.1.0

1.1.0.0

  Sources   Download

MIT

The Development Requires

by Lars Vierbergen

22/07 2013

1.0.0

1.0.0.0

  Sources   Download

MIT

The Development Requires

by Lars Vierbergen

20/06 2013

0.1.0

0.1.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Lars Vierbergen