PHPackages                             blablacar/twig-stamp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. blablacar/twig-stamp

AbandonedLibrary[Templating &amp; Views](/categories/templating)

blablacar/twig-stamp
====================

Put a stamp placeholder in a base template, fill it from anywhere.

4108.3k↓27.3%PHP

Since Mar 29Pushed 8y ago42 watchersCompare

[ Source](https://github.com/blablacar/twig-stamp)[ Packagist](https://packagist.org/packages/blablacar/twig-stamp)[ RSS](/packages/blablacar-twig-stamp/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Twig Stamp
==========

[](#twig-stamp)

Put a placeholder in a base template, fill it from anywhere.

Idea
----

[](#idea)

One of our front mates needs to dump SVG sprites on our base layout, but don't want to dump all our icons: only the SVGs that are actually used in the whole page, on demand. The problem here is that our pages are complex, with lots of `{% include %}`, `{% render %}` and other features that doesn't let us easily track what are the required SVG icons and dump them at the top of the base layout.

This Twig extension adds the ability to put a placeholder somewhere in a base layout, and to put something inside from any page of the application whatever his scope and independence.

Example
-------

[](#example)

To simplify, imagine that we want to create a page having a table of contents (toc) at the top, generated based on what's inside the page.

The main layout:

```
{# demo.twig #}
{% stamp 'toc' %}

{# here is the placeholder where we want the table of contents dumped #}
{% stamp_dump 'toc' %}

{{ include('section1.twig') }}
{# ... #}

{% endstamp %}
```

One section:

```
{# section1.twig #}
{# Here, we add a stamp that will be dumped in the placeholder later on #}
{{ stamp_use('toc', 'Section 1') }}

Lorem ipsum dolor sit amet, eu vel aliquam adversarium...
```

The table of contents:

```
{# toc.twig #}
Table of contents

    {% for title in list %}
        {{ title }}
    {% endfor %}

```

Now we need to create the logic:

```
