Download the PHP package performing/twig-components without Composer

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

Twig components extension

Packagist Version Tests Packagist Downloads

This is a PHP package for automatically create Twig components as tags. This is highly inspired from Laravel Blade Components.

Installation

You can install the package via Composer:

Configuration

This package should work anywhere where Twig is available.

To enable the package just pass your Twig environment object to the function and specify your components folder relative to your Twig templates folder.

Configuration for Craft CMS

In Craft CMS you should do something like this:

The if statement ensure you don't get 'Unable to register extension "..." as extensions have already been initialized' as error.

Configuration for Symfony

In Symfony you can do something like this:

Configuration for October CMS / Winter CMS

In October CMS and Winter CMS you need to hook into cms.page.beforedisplay event inside your plugin's boot method in order to access Twig instance.
Then you can use your plugin hint path to choose a views subfolder as components' folder.

All features, like subfolders are supported. For example <x-forms.input></x-forms.input> will refer to plugins/namespace/pluginname/views/forms/input.twig.

Usage

Components are just Twig templates in a folder of your choice (e.g. /components) and can be used anywhere in your Twig templates:

The slot variable is any content you will add between the opening and the close tag.

To reach a component you need to use the dedicated tag x followed by : and the filename of your component without extension:

It will render:

Custom tags

The same behaviour can be obtained with a special HTML syntax.

Attributes

You can also pass any params like you would using an include. The benefit is that you will have the powerful attributes variable to merge attributes or to change your component behaviour.

With custom tags you can pass any attribute to the component in different ways. To interprate the content as Twig you need to prepend the attribute name with a :, but it works also in other ways.

Subfolders

To reach components in subfolders you can use dot-notation syntax.

Named slots

In case of use of multiple slots you can name them.

Use with standard syntax:

Use with custom tags syntax:

Twig namespaces

In addition to the specified directory, you can also reference components from a Twig namespace by prepending the component name with <namespace>:.

Use with standard syntax:

Use with custom tags syntax:

Dynamic components

Sometimes you may need to render a component but not know which component should be rendered until runtime.
In this situation, you may use the built-in dynamic-component to render the component based on a runtime value or variable:

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Testing

License

The MIT License (MIT). Please see License File for more information.


All versions of twig-components with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
twig/twig Version ^3.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 performing/twig-components contains the following files

Loading the files please wait ....