Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

Add a better t filter to pattern lab so it plays well with Drupal #56

Merged
merged 1 commit into from
Apr 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions components/_twig-components/filters/t.filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
* Bring Drupal filters in just so Pattern Lab doesn't bork.
*/

$filter = new Twig_SimpleFilter('t', function ($string) {
return $string;
$filter = new Twig_SimpleFilter('t', function ($string, $array = array()) {
if (is_string($string) && is_array($array)) {
$haystack = $string;
foreach ($array as $needle => $replace) {
$haystack = str_replace($needle, $replace, $haystack);
}
return $haystack;
}
});