VV::embed()

Inline the contents of any file.

This can be very useful for bundling SVGs, plaintext files, HTML, and more for faster page loading.

Parameters

string

$pathname

Path to an asset to inline.

bool

$relative

Flag which when set to:

  1. true

    Will make $pathname look for a file relative to root_path.

  2. false

    Will make $pathname look for a file relative to the root of the whole filesystem.

Return value

string

Returns the contents of a file passed to $pathname as a string. If a file can not be found at $pathname, an empty string is returned.


Examples

Inlining an SVG icon

In this example we will be inlining an SVG icon from /public/assets/icon.svg directly into our page as if it were hardcoded.