Download the PHP package ju1ius/twig-buffers-extension without Composer

On this page you can find all versions of the php package ju1ius/twig-buffers-extension. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package twig-buffers-extension

Twig Buffers Extension

codecov

This extension allows you to define buffers into which you can insert content from another part of the template or from included, embedded or child templates. It is similar in functionality to Blade stacks.

Installation

Basic usage

Let's start with what will probably be the most frequent use case.

Given the following templates:

Rendering page.html.twig

Will output:

The buffer tag

The buffer tag does two things:

A named buffer can therefore be referenced several times:

By default, the contents of the buffer are joined using the empty string, but you can customize the joining string:

You can also provide a «final glue», similarly to the join twig filter:

As we just saw, even when using automatic escaping, the joining strings will not be automatically escaped. You'll have to escape them yourself if they come from untrusted sources:

Inserting content into buffers

This is done via the append and prepend tags. They share the same syntax apart from their respective tag names.

As with the block tag, you can use a short or a long syntax:

As the name implies, the append tag appends content to the buffer.

The prepend tag however, doesn't prepend content to the buffer, but instead appends content to the head of the buffer:

Trying to insert content into a buffer that does not exist or is not in scope will throw an UnknownBuffer exception.

Inserting to potentially undefined buffers

If you want to insert content into a buffer that may not exist or may not be in scope, you have two solutions:

1.

If `my_buffer` doesn't exist or is not [in scope](#the-scope-of-a-buffer),
this is a no-op.

2.

If `my_buffer` doesn't exist or is not [in scope](#the-scope-of-a-buffer),
first open the buffer, then insert content into it.

Unique insertions

You can tag insertions with a unique id in order to prevent the same content to be inserted more than once.

Clearing the contents of a buffer

You can use the clear_buffer function:

Attempting to clear the content of a buffer that does not exist or is not in scope will throw an UnknownBuffer exception.

Checking if a buffer exists

You can use the buffer test:

The buffer test will return true if the buffer exists and is in scope.

Checking if a buffer is empty

You can use the empty_buffer test:

Or for a more practical example:

The empty_buffer test will return true if:

The scope of a buffer

When a template contains a {% buffer %} tag, the corresponding buffers are opened as soon as the template begins to render.

Once opened, a buffer remains available until the end of the topmost render call.

Therefore, a buffer is available:

  1. in the whole template it is referenced in and in all it's included, embedded or child templates.
  2. in all subsequent siblings of the template it is referenced in.

To clarify, lets look at some examples.

The following works because of rule n°1:

The following also works because of rule n°1:

The following works because of rule n°2:

However, because of rule n°2, the following does not work:


All versions of twig-buffers-extension with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
twig/twig Version ^3.15
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ju1ius/twig-buffers-extension contains the following files

Loading the files please wait ....