Skip to content

Commit 888d69c

Browse files
committed
Merge branch 'dev'
2 parents 7dccd3d + ca899ee commit 888d69c

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Twig PatternEngine for Pattern Lab PHP
2+
3+
The Twig PatternEngine allows you to use [Twig](http://twig.sensiolabs.org) as the template language for Pattern Lab PHP. Once the PatternEngine is installed you can use Twig-based StarterKits and StyleguideKits.
4+
5+
## Installation
6+
7+
Pattern Lab PHP uses [Composer](https://getcomposer.org/) to manage project dependencies. To install the Twig PatternEngine:
8+
9+
composer require pattern-lab/patternengine-twig
10+
11+
## Available Loaders
12+
13+
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.
14+
15+
### The String Loader
16+
17+
The string loader takes a simple string and compiles it. To use:
18+
19+
```php
20+
$data = array("hello" => "world");
21+
$string = "If I say hello you say {{ hello }}.";
22+
$stringLoader = \PatternLab\Template::getStringLoader();
23+
$output = $stringLoader->render(array("string" => $string, "data" => $data));
24+
print $output; // outputs "If I say hello you say world."
25+
```
26+
27+
### The Filesystem Loader
28+
29+
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:
30+
31+
```php
32+
$data = array(...);
33+
$filesystemLoader = \PatternLab\Template::getFilesystemLoader();
34+
$output = $filesystemLoader->render(array("template" => "viewall", "data" => $data));
35+
print $output; // outputs the viewall view from the configured styleguidekit
36+
```
37+
38+
### The Pattern Loader
39+
40+
The pattern loader looks for patterns and allows the use of the Pattern Lab-specific partial syntax. To use:
41+
42+
```php
43+
$data = array(...);
44+
$patternPath = "path/to/pattern";
45+
$patternEngineBasePath = \PatternLab\PatternEngine::getInstance()->getBasePath();
46+
$patternLoaderClass = $patternEngineBasePath."\Loaders\PatternLoader";
47+
$patternLoader = new $patternLoaderClass($options);
48+
$code = $patternLoader->render(array("pattern" => $patternPath, "data" => $data));
49+
print $output; // outputs the given pattern

src/PatternLab/PatternEngine/Twig/Loaders/FilesystemLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct($options = array()) {
3434
*/
3535
public function render($options = array()) {
3636

37-
return $this->instance->render($options["template"], $options["data"]);
37+
return $this->instance->render($options["template"].".twig", $options["data"]);
3838

3939
}
4040

src/PatternLab/PatternEngine/Twig/Loaders/Twig/PatternLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*/
1313

14-
namespace PatternLab\TwigPatternEngine;
14+
namespace PatternLab\PatternEngine\Twig\Loaders\Twig;
1515

1616
use \PatternLab\PatternEngine\Util;
1717

0 commit comments

Comments
 (0)