getgrav / grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony
https://getgrav.org
MIT License
14.57k stars 1.41k forks source link

Get the source of SVG file #2700

Open alexljamin opened 5 years ago

alexljamin commented 5 years ago

All of these commands return <img ... /> attribute:

  1. {{ media['theme://images/name.svg'] }}
  2. {{ media_directory('theme://images')['name.svg'] }}
  3. {{ page.media['theme://images/name.svg'] }}
  4. {{ media['theme://images/name.svg'].display('source') }}

But I need to get contents of the SVG shown inline in DOM with something like this: {{ source("theme://images/name.svg") }}

Currently it returns:

"Template "theme://images/name.svg" is not defined."

I have checked this and that but none of the questions do not really have an answer relevant to my issue.

What will be the correct syntax to return the content of SVG?

rhukster commented 5 years ago

You can use use include:

https://github.com/getgrav/grav-theme-quark/blob/develop/templates/partials/logo.html.twig#L7

rhukster commented 5 years ago

BTW the @images namespace is defined in that theme class’s here https://github.com/getgrav/grav-theme-quark/blob/develop/templates/partials/logo.html.twig#L7

It s optional but include will not know how to resolve the theme:// stream without it.

alexljamin commented 5 years ago

Thank you for your quick response @rhukster ! In your second response you have shared the exact same URL as in your first answer. I am not able to find the @images namespace definition in that link.

Is that what I should be looking at https://github.com/getgrav/grav-theme-quark/blob/develop/quark.php#L24 ?

Duplicating the @images namespace in this class seem to work. Will you be open if I add this information to docs - https://learn.getgrav.org/16/themes/asset-manager#static-assets?