This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Is there a way to pass through a multidimensional array to a twig filter with registerMarkupTags ?
So I'd like to be able to do something like
{{ variable_name | my_filter(['key' => 'value']) }}
In my registerMarkupTags method looking like this
public function registerMarkupTags()
{
return [
'filters' => [
'my_filter' => ['Path/To/A/Class', 'handle']
]
];
}
And then the handle method
public static function handle($variable, $options = [])
{
/* code */
}
The problem with this is that i'm getting the following error
An array element must be followed by a comma. Unexpected token "arrow function" of value "=>" ("punctuation" expected with value ",").
Last updated
mjauvin said:
see https://www.google.com/amp/s/mijingo.com/blog/key-value-arrays-in-twig/amp
Yep - thanks for this man, i just came back here to let everyone know that i'd figured this out....
So basically you just pass data through like this....
{{ variable_name | my_filter({'key1':'value1','key2':'value2' }) }}
And then in the handler method you get this...
public function handle($variable_name, $array) { ... }
And array will look like this...
[ 'key1' => 'value1', 'key2' => 'value2' ]
That's a cool article too so i'll definitely check that too. Thank you!
1-4 of 4