Meta Box
Support Forum
Support › MB Views › Display SVGs with file_get_contents?Resolved
Is there a way I can display SVG files with PHP's file_get_contents function? Currently, I'm just using an image tag pointing to the SVG, but would prefer to have the generated HTML have the "standard" SVG tag, etc.
Thanks, AJ
Hi,
You can run a PHP function in View via the proxy mb. Refer to this documentation https://docs.metabox.io/extensions/mb-views/#running-php-functions and this topic https://stackoverflow.com/questions/21314915/getting-data-from-an-svg-file-using-php
mb
{{ mb.file_get_contents('https://cdn.shopify.com/s/files/1/0496/1029/files/Freesample.svg') }}
I think the next issue I'll run into is adding the title attributes to the SVG. I found https://kevin-ang.medium.com/inline-svg-system-in-wordpress-or-php-development-838dad423e76 and it has pretty good documentation on how I can achieve what I want, but can MetaBox run custom functions or just built-in WordPress functions?
Yes, you can run a custom function in the View as well.
function my_function() { return "My Custom Function!!!"; }
View: {{ mb.my_function() }}
{{ mb.my_function() }}