Add dynamic data to SVG element

Bricks Version: 1.4


It’s impossible to use dynamic data for SVG element, so it is impossible to use this element in a loop for displaying custom SVG for CPT.

This is very frustrating because using Image element doesn’t allow to change fill or stroke color.

Does someone know a quick alternative for this???

I guess we could copy the whole svg code in a textarea custom field, but it seems a bit brutal…

1 Like

Hi Yan,
where is the bug? Either this is a how-to question, or a feature request :wink:

I use ACF and for the SVG a file field (return type file array) and the following code in a code element in my loop:


  $icn = get_field('custom_svg');

	if($icn) {
      $icnUrl = $icn['url'];
      $icnID = $icn['ID'];

      echo file_get_contents($icnUrl, $icnID);

Throws possibly a warning in the builder but works in the frontend :sunglasses:
Perhaps there is a better solution.

Best regards,


Brilliant, thank you!

I was using SVG code in metabox text field because I didn’t want to add http request for each SVG file, but your code renders SVG inline, awesome!
And glad to discover file_get_contents function :slight_smile:

(By the way I don’t understand your $icnID arg, which doesn’t seem to match documentation… I only use url param and it is working perfectly without any warning.)

And yes, you’re right, more a feature request, but as dynamic data is available for bitmap images, I consider this a defect. Anyway, EDITED.

Without the second parameter, a PHP notice was issued. No idea what the reason is, but if it works without too: cool!