Including SVG contents in Laravel 5 Blade template

Michael Lawton picture Michael Lawton · May 5, 2015 · Viewed 23.2k times · Source

What is the best way to include the contents of an SVG file (located in the assets folder) in a Laravel 5 blade template?

I don't want to use image/object/embed tags, this should be an inline SVG for reasons of speed.

I know I could use <?php file_get_contents("file.svg") ?> but is there a better way specific to Laravel/Blade?

Edit: to clarify, the method should work with all SVG files, including the one below.

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg">
<path stroke="red" fill="#00f" d="M10 10h100v100H10z"/>
</svg>

Answer

Romain picture Romain · Nov 11, 2015

This works, that's the simplest way I could think about :

{!! file_get_contents('images/icon.svg') !!}