Download the PHP package pattern-lab/patternengine-twig without Composer

On this page you can find all versions of the php package pattern-lab/patternengine-twig. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package patternengine-twig

Twig PatternEngine for Pattern Lab

The Twig PatternEngine allows you to use Twig as the template language for Pattern Lab PHP. Once the PatternEngine is installed you can use Twig-based StarterKits and StyleguideKits.

Installation

The Twig PatternEngine comes pre-installed with the Pattern Lab Standard Edition for Twig. Please start there for all your Twig needs.

Composer

Pattern Lab PHP uses Composer to manage project dependencies with Pattern Lab Editions. To add the Twig PatternEngine to the dependencies list for your Edition you can type the following in the command line at the base of your project:

composer require pattern-lab/patternengine-twig

See Packagist for information on the latest release.

Overview

This document is broken into three parts:

Working with Patterns and Twig

Twig provides access to two features that may help you extend your patterns, macros and layouts viatemplate inheritance. The Twig PatternEngine also supports the pattern partial syntax to make including one pattern within another very easy.

Pattern includes

Pattern includes take advantage of the pattern partial syntax as a shorthand for referencing patterns from across the system without needing to rely on absolute paths. The format:

For example, let's say we wanted to include the following pattern in a molecule:

The pattern type is atoms (from 00-atoms) and the pattern name is landscape-16x9 from (from 02-landscape-16x9.twig). Pattern sub-types are never used in this format and any digits for re-ordering are dropped. The shorthand partial syntax for this pattern would be:

Macros

The requirements for using macros with Pattern Lab:

Please note: ensure that there is no overlap between the keys for your macros and the keys for your data attributes. A macro with the name forms.macro.twig will conflict with a root key with the name forms in your JSON/YAML. Both are accessed via {{ forms }} in Twig.

An example of a simple macro called forms.macro.twig in source/_macros:

Would be used like this in a pattern:

Template inheritance

How to use Template Inheritance with Pattern Lab:

An example of a simple layout called base.twig in source/_layouts:

Would be used like this in a pattern:

All uses of extends above also work with includes, embed and most likely many other Twig Tags. Let us know if you run into interesting or unexpected use cases!

Extending Twig Further

Twig comes with a number of ways to extend the underlying template parser. You can you can add extra tags, filters, tests, and functions. The Twig PatternEngine tries to simplify these extensions by allowing you to create files in specific folders and then auto-load the extensions for you. Learn more about:

You can also:

Filters

The requirements for using filters with Pattern Lab:

An example function called rot13.filter.php in source/_twig-components/filters:

This filter would be used like this in a pattern:

Functions

The requirements for using functions with Pattern Lab:

An example function called boo.function.php in source/_twig-components/functions:

This function would be used like this in a pattern:

Tests

The requirements for using tests with Pattern Lab:

An example of a simple test called red.test.php in source/_twig-components/tests:

This test would be used like this in a pattern:

Where the JSON for the data to set shirt would be:

Reminder: all data in Pattern Lab is stored as an array and not as an object. So $object->attribute won't work in tests.

Tags

The requirements for using tags with Pattern Lab:

Tags are the most complicated extension to set-up with Pattern Lab. Three steps are needed to define a new tag in Twig:

Pattern Lab takes care of the registering for you based on the file name.

An example of a simple tag called setdupe.tag.php in source/_twig-components/tags that mimics the default set tag. Please note all of the locations where class names incorporate the filename, setdupe.

This tag would be used like this in a pattern:

Adding a custom Twig Extension

A Twig Extension is a collection of Twig functions, filters, tags, globals, and tests all as a single bundle. This approach is more advanced than adding a single function or filter using the above method, but allows greater flexibility as the whole Twig Extension can be installed in multiple environments.

To add a Twig Extension using the PHP class \MyProject\MyCustomTwigExtension, add this to config.yml:

What happens under the hood is basically this:

If two Twig Extensions declare a function, filter, etc; the later ones override earlier ones. Any ones declared in Pattern Lab's _twig-components folder will override any declared using this method of custom Twig Extensions.

For an example of how this works, see ExampleTwigExtension.php in this repo. You can enable it by adding this to your config.yml:

Then place this in any Twig file:

That function declaration looks like this in ExampleTwigExtension.php:

An incredible amount of exciting possibilities are enabled with this; have fun!

Enable dump()

To use dump() set twigDebug in config/config.yml to true.

Modify the Default Date and Interval Formats

You can modify the default date and interval formats for Twig by editing the twigDefaultDateFormat and twigDefaultIntervalFormat in config/config.yml. Set them to an empty string to use Twig's default formats. Please note: both must be set for this feature to work.

Quickly Disable Extensions

To disable extensions that you're no longer using simply add an underscore to the beginning of a filename and then re-generate your site. For example, the enabled rot13 filter:

source/_twig-components/filters/rot13.filter.php

And the disabled rot13 filter:

source/_twig-components/filters/_rot13.filter.php

Then re-generate your Pattern Lab site with:

php core/console --generate

Available Loaders

If you're building a plugin that will be parsing Twig files you have access to three loaders. It's recommended that you use these instead of accessing Twig directly as these loaders will work with other PatternEngines.

The String Loader

The string loader takes a simple string and compiles it. To use:

The Filesystem Loader

The filesystem loader will look for templates in the configured StyleguideKit directory and compile them. The template location for the filesystem loader can't be modified. To use:

The Pattern Loader

The pattern loader looks for patterns and allows the use of the Pattern Lab-specific partial syntax. To use:


All versions of patternengine-twig with dependencies

PHP Build Version
Package Version
Requires pattern-lab/core Version ^2.0.0
twig/twig Version ~1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package pattern-lab/patternengine-twig contains the following files

Loading the files please wait ....