Download the PHP package oofbar/craft-twig-toolbox without Composer

On this page you can find all versions of the php package oofbar/craft-twig-toolbox. 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 craft-twig-toolbox

Twig Toolbox for Craft CMS

The simplest way to keep business logic out of your Twig templates.

All this plugin does is registers a Twig extension—everything else is up to you! With Twig Toolbox, you can finally start to clean up the mess that accumulates at the top of every template…

Usage

Twig Toolbox lets you inject custom filters, functions, globals, and tests into Craft’s template engine.

To get started, install the plugin from the Craft Plugin Store, or use Composer:

Then, copy this into config/twig-toolbox.php:

:bulb: If you’re in the mood for a challenge, writing your own Twig extension is a great way to get familiar with custom module development.

Let’s look at some examples of how each language feature can be used.

Filters

→ Documentation on Twig Filters

The filters key should contain alphanumeric keys and functions or callables as values. Filters always have at least one argument!

Example

Functions

→ Documentation on Twig Functions

Each item in the functions array should have an alphanumeric key, and a function as its value. The function needs to declare expected arguments, and should explicitly return a value, if appropriate.

:smile: You can use virtually any Craft API in a function!

Example:

Globals

→ Documentation on Twig Globals

Globals are best used sparingly, and only for simple values. The new custom config in Craft 4 is a near equivalent!

:warning: Be mindful of what you are assigning to a global! Calling some Craft or Plugin APIs can cause a race condition as the system initializes.

Example:

Tests

→ Documentation on Twig Tests

Tests are sort of like functions, but only available when using Twig’s is operator. They can do a lot to make your templates read more clearly—especially when the logic behind it is convoluted.

Examples

Tips + Tricks

Callables

PHP has a special “type” for callable values. This includes the anonymous functions or “closures” we’ve used so far, in addition to a few other syntaxes that make it simple to add proxies to native PHP and Craft functions:

Handling Types

Some of the functions above could be made even more flexible by accepting the special mixed type, or a union type. For example, the expensive test could do some type checking and normalization like this...

...then, the template can read a bit more fluidly:

Parameterization

filters and functions can take arguments to customize their behavior. If you find yourself adding a number of similar helpers, take a moment to consider how they could be consolidated and parameterized with one or more arguments.

HTML Helpers

Consider how Twig can help you generate HTML, rather than trying to build it up yourself!

Help + Support

If you’re having trouble getting started, create an issue on GitHub and we’ll do our best to help out! If you need support on a project-specific task (like finding the appropriate Craft APIs), we recommend posing it to the broader community.


All versions of craft-twig-toolbox with dependencies

PHP Build Version
Package Version
Requires craftcms/cms Version ^4.0.0 || ^5.0.0
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 oofbar/craft-twig-toolbox contains the following files

Loading the files please wait ....