patternengine-php-twig icon indicating copy to clipboard operation
patternengine-php-twig copied to clipboard

Add "Globals" Twig Extension Support

Open sghoweri opened this issue 8 years ago • 1 comments

https://twig.symfony.com/doc/2.x/advanced.html#id1

This update will continue to unlock even more interesting options for us in cross-platform Design System interoperability -- especially with things like shared Design Tokens, schema data, default inherited properties (cough Drupal Attributes cough), and more. Addresses #46

Example of this being used out in the wild (ex. sharing the default responsive img srcset breakpoint sizes): https://github.com/bolt-design-system/bolt/blob/develop/packages/bolt-twig-extensions/globals/bolt-image-sizes.global.php

CC @aleksip @bradfrost

Side question / point of interest: Note that this extension, unlike the other Twig extension integrations in Pattern Lab, doesn't require us to use some $function = new Twig_SimpleFunction('NAME', function ($params) { ... }); wrapper -- potentially allowing opening the door for other Twig functions, filters, tags, tests and operators to get added in the same manner (ie. the same extension getting used in another environment supporting Twig could perhaps just get dropped in verbatim)

sghoweri avatar Nov 04 '17 18:11 sghoweri

Hmm... now that I'm looking at this closer, I'm not too big of a fan of making a new Twig Extension for each global file. I'd prefer if we just used $self::$instance->addGlobal().

EvanLovely avatar Feb 05 '18 22:02 EvanLovely