how to set twig global default variable -
is there way set global default variable instead of setting each 1 ?
{{ app.model.foo | default('not set') }} {{ app.model.bar | default('not set') }}
the built-in default filter cannot wish achieve. here's complete code:
function _twig_default_filter($value, $default = '') { if (twig_test_empty($value)) { return $default; } return $value; }
but twig easy extend! can create own twig extension, registers new filter, code of this:
function my_default_filter($value, $default = '') { if (twig_test_empty($value)) { return $default ?: $this->default; } return $value; }
where class has $default
property can set code, want.
Comments
Post a Comment