Download the PHP package treztreiz/twig-components without Composer

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

A lightweight, framework-free Twig component syntax layer.

Write components as HTML-like tags in your Twig templates — no Symfony, no bundle, no framework dependency. The library rewrites <twig:name /> and <twig:name>…</twig:name> into native Twig before the engine tokenizes the template, so it slots into any Twig 3.x project.


Requirements

No framework required.


Installation


Wiring

Filesystem layout:

Component names are resolved as PascalCase: <twig:my-card /> → MyCard.html.twig. Use colons as directory separators: <twig:ui:alert /> → components/Ui/Alert.html.twig.

Cache note: Twig only rechecks template freshness when auto_reload is enabled. Without it, editing a component template won't take effect until the compiled cache is cleared. Enable auto_reload in development; in production, clear cache/ on deploy.


Syntax

Self-closing (no children)

Props become variables inside the component template. All props are also available as an attrs bag (see Attribute passthrough).

Non-self-closing (with children / slots)

The children become the content block. The component template uses {% embed %} under the hood, so standard Twig block semantics apply.

Named slots

Children before the first named slot become the content block automatically.

Dynamic props

Prefix a prop with : to pass a Twig expression instead of a string literal:

Boolean props

Bare attribute names map to true:

Subdirectory components

Use colons to reference components nested in subdirectories:

<twig:ui:alert /> → components/Ui/Alert.html.twig. Kebab segments work too: <twig:my-ui:form-input /> → components/MyUi/FormInput.html.twig.

Twig interpolation in static values

Parent context access

Components are isolated by default — they only see the props you pass. Add the bare context flag to opt a component into reading its parent's scope through a single context bag:


Props

Use {% props %} inside a component template to declare which variables are component-specific props. Declared props are extracted as named variables and automatically stripped from attrs, leaving only the remaining HTML attributes for passthrough.


Attribute passthrough

Every component receives an attrs variable — a ComponentAttributes instance built from all the props passed at the call site.

attrs is HTML-safe; use it without |raw.

Filtering:

Method Returns
attrs.only('a', 'b') new instance with only those keys
attrs.without('a', 'b') new instance without those keys
attrs.has('class') bool
attrs.get('class', 'default') scalar or null
attrs.all() raw array

Defining block structure in component templates

Use <twig:block> inside component templates as a shorthand for {% block %}:

Standard {% block %} syntax still works and is unchanged.


Known limitations


Comparison with Symfony TwigComponent

Feature treztreiz/twig-components Symfony Twig Components
Framework requirement None Symfony + UX bundle
PHP class per component No Yes (optional with anonymous components)
Computed properties / service injection No Yes, via mount() and DI
Template-only (anonymous) components Yes (always) Yes (opt-in)
<twig:name /> syntax Yes Yes
Named slots / blocks Yes Yes
Attribute passthrough (attrs) Yes Yes
Dynamic props (:prop="expr") Yes Yes
Boolean props Yes Yes
{% props %} tag Yes Yes
Subdirectory components (ui:card) Yes Yes
LiveComponent (reactive, JS binding) No Yes (separate package)
Stimulus / Turbo integration No Yes
Works without Composer autoloading magic Yes No
Cache-safe (compiled template invalidation) Yes Yes

Choose treztreiz/twig-components if:

Choose Symfony TwigComponent if:


License

MIT


All versions of twig-components with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
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 treztreiz/twig-components contains the following files

Loading the files please wait ...