Svgs aren't rendered from readFile function inside shortcode

Hello everyone,
seems like I’m here every couple of days now. I wanted to ask you about the readFile function, which I’m not capable or having it output the content of an SVG that I saved in the assets directory.
Here’s the shortcode

<pre class="inline-svg">
{{ $icon := resources.Get "SVGs/linux.svg" }}
{{ $icon | absURL | readFile | safeHTML }}
</pre>

which is called by a simple {{< svg >}}.
I’m trying to keep it simple here, and that’s the reason why is inside a <pre> block, I’m trying to figure out how this works.

the icon is inside the theme’s assets directory, here’s a tree view:

themedir
	├── assets
	│	 ├── SVGs
	│	 │	 ├── arrow-up.svg
	│	 │	 ├── css3.svg
	│	 │	 ├── git.svg
	│	 │	 ├── github.svg
	│	 │	 ├── home.svg
	│	 │	 ├── html5.svg
	│	 │	 ├── instagram.svg
	│	 │	 ├── js.svg
	│	 │	 ├── linux.svg
	│	 │	 ├── markdown.svg
	│	 │	 ├── sass.svg
	│	 │	 ├── spotify.svg
	│	 │	 └── twitter.svg
[...]

but readFile keeps returning nothing at all.
How can I debug the paths that are evaluated by the various functions? Is there a way to have a function output some more detailed errors when it doesn’t work?

Lastly, here’s the repository on github, in case you want to test it:

Thanks a lot in advance
cheers.

Your SVG already living under assets mount, you can access it’s .Content directly after you get it.

<pre class="inline-svg">
{{ $icon := resources.Get "SVGs/linux.svg" }}
{{ $icon.Content | safeHTML }}
</pre>
1 Like

thanks a lot man!!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.