Skip to content

diasfs/twig-relative-path

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twig Relative Path Extension

An extension for Twig that allows to include and extends templates using relative paths.

Instalation

composer require diasfs/twig-relative-path

Initialization

use Twig\Extension\RelativePathExtension;
use Twig\Environment;

...

$twig = new Environment($loader);
$twig->addExtension(new RelativePathExtension());

Example

{# layout.html.twig #}
<!DOCTYPE html>
<html>
    <head>
        ...
    </head>
    <body>
        {% block content '' %}
    </body>
</html>

{# pages/inc/form.html.twig #}
<form>
    ...
</form>


{# pages/page.html.twig #}
{% extends "../layout.html.twig" %}

{% block content %}
    {% include './inc/form.html.twig' %}
{% endblock %}

The resulting html will be the following:

<!DOCTYPE html>
<html>
    <head>
        ...
    </head>
    <body>
        <form>
            ...
        </form>
    </body>
</html>

License

The library is released under the MIT License. See the bundled LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages