Utilizing Drupal 8, I’ve a media discipline the place somebody can add an SVG file.
I’ve this discipline show set to output because the URL path to the file.
I am making an attempt to get this worth as a string (at the moment it is a render array) so I can name it with {% embody var %}
and embed the SVG straight into the DOM.
For instance, I’ve this code. (I am utilizing twig_field_value.)
field_value %
If I render the variable within the template with {{ var }}
, it spits out a string onto the display screen, for instance /websites/default/recordsdata/pathto/file.svg.
If I manually copy-paste this string into my twig template, e.g. {% embody '/websites/default/recordsdata/pathto/file.svg'%}
, it really works completely, similar to I need. Nonetheless, I wish to use {% embody var %}
, which is inflicting a PHP error as a result of it might probably’t embody a template file as a result of the var is definitely an array.
This discipline can solely have a single worth.
What I want is determining learn how to convert this into an precise string so I can use it with embody
.