Download the PHP package wabisoft/craft-bonsai-twig without Composer

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

Bonsai Twig Plugin

Welcome to the Bonsai Twig Plugin README! This plugin is designed as a development-only tool to streamline your Twig templating experience by providing hierarchical template loading for various element types in Craft CMS 5.

Features

Function Reference

Each loader has its own doc with the full parameter list, resolution hierarchy, and a pure-Twig replacement if you ever remove the plugin:

Also: CHANGELOG.md

Requirements

Getting Started

1. Install

The plugin ships inside the project as a Composer path repository:

2. Add your first template tree

Call a loader where you'd normally write an {% include %}:

Then create templates under templates/_entry/. Bonsai tries paths from most to least specific and renders the first one that exists:

Start with a single _entry/{section}/default.twig and add more specific templates only where a page needs to differ — no template calls change, resolution picks them up automatically.

The same pattern applies to the other trees: _matrix/, _category/, _item/, _asset/, _product/ — each with its own loader function (see Usage Guide).

3. See what's resolving

Add ?beastmode to any URL (or press Cmd+B) to see every path tried and which one won. For AI agents reading page source, enable LLM trace comments instead.

Template Resolution Strategy (v8.0)

By default, templates resolve section-first (entry/{section}/{type}/...). In v8.0, you can opt into type-first resolution (entry/{type}/{section}/...), aligning with Craft 5's standalone entry types.

Setting the Strategy

Three levels of configuration (highest to lowest precedence):

1. Per-template (highest priority):

2. Config file:

3. Control Panel:

Radio buttons in Settings > Bonsai Twig > Template Resolution Strategy.

If unset at all levels, defaults to 'section' — identical behavior to v7.

Path Resolution Comparison

For an entry with section blog and type article:

Priority Section-first (default) Type-first
1 _entry/blog/article/{slug} _entry/article/blog/{slug}
2 _entry/blog/article/_entry _entry/article/blog/_entry
3 _entry/blog/{slug} _entry/article/{slug}
4 _entry/blog/article _entry/article/blog
5 _entry/blog/default _entry/article/default
6 _entry/blog _entry/article
7 _entry/article _entry/blog
8 _entry/default _entry/default

Strategies can be mixed — set a global default, then override per template call or per section. Patterns in readme-item.md.

Which Loaders Support Strategy?

Loader Strategy support
entryTemplates() Yes
itemTemplates() Yes (item + ctx dimensions)
matrixTemplates() No (already type-centric)
categoryTemplates() No (legacy, no entry types)
assetTemplates() No (volume/folder based)

Usage Guide

Six loader functions, one pattern: pass the element, get the most specific template that exists. Each heading links to the full reference (all parameters, complete hierarchy).

Entry — entryTemplates()

Category — categoryTemplates()

Item — itemTemplates()

For related/nested entries; style participates in path resolution.

Matrix — matrixTemplates()

Style-, handle-, context-, and position-aware. Pass loopIndex/loopLength to expose a loop variable inside block templates.

Asset — assetTemplates()

Resolves by volume → folder → filename.

Product — productTemplates()

Template Path Display — btPath()

Returns a self-styled HTML block listing every attempted path with the resolved one marked ✓. Call it anywhere in a template — no wrapping needed; returns an empty string in production.

Debug Features

The plugin provides debugging tools that are only active in development mode (devMode = true).

Debug Mode

Keyboard Shortcut (Recommended)

Press Cmd+B (Mac) or Ctrl+B (Windows/Linux) to open the Beastmode options modal. This lets you select which template types to debug without manually editing the URL.

URL Parameter

Add ?beastmode to any URL to enable debug mode for all template types:

Or filter by specific types (comma-separated):

Valid types: entry, category, item, matrix, asset, product, or all

Debug Information Display

When debug mode is active, you'll see clean debug output showing:

Template Resolution Information

The debug output focuses on essential information without performance metrics or complex styling.

Every loader call gains the overlay automatically — no template changes needed.

LLM Trace Comments (v9.3)

When enabled, every Bonsai-resolved render is bracketed in machine-parseable HTML comments mapping the rendered DOM back to the winning template and its resolution context — the same map the beastmode overlay shows, but inline in the page source, consumable by an LLM/agent:

Pairs match on id (a per-page nonce + counter, so page content can't forge plausible pairs); nested loader calls yield nested pairs, so the comment tree mirrors the render tree. A page-level <!-- bonsai:trace v="1" nonce="…" --> marker is emitted whenever tracing is active — even on pages with no Bonsai renders. Comments carry paths, ids, and handles only — never field values.

The full attribute grammar lives in example.CLAUDE.md — the one file consuming agents read.

Enabling

Two independent conditions, both required:

llmMode is the switch; devMode is the safety floor — trace comments never render in production, even with BONSAI_LLM_MODE=true in a production .env.

Staging caveat: tried enumerates your template tree and content-model handles in every page's source. Don't enable llmMode on internet-reachable staging servers that run devMode=true.

Enable via any of (precedence: env > config file > CP setting):

Or toggle "LLM trace comments" in the plugin's CP settings.

Opting out (non-HTML contexts)

A wrapped template rendering into JSON-LD, <script>, <style>, <title>, an attribute value, or whitespace-sensitive output (<pre>) would be corrupted by an HTML comment:

Labelling static components

Trace comments mark dynamic resolutions only — plain {% include %}s are followed by reading source. For components included through dynamic names (or just for convenience), templates can self-label using bonsaiTraceEnabled(), which gates on the same devMode + llmMode switch:

Agent consumption recipe

example.CLAUDE.md is a ready-to-append snippet for a consumer project's CLAUDE.md — the comment grammar, how to fetch raw source, nesting semantics, and how to read a fallthrough:

Integration with Craft 5

Unified Element Model

In Craft CMS 5, categories are now entries, which simplifies template handling. The plugin automatically handles this unification while maintaining backward compatibility.

Integration with Craft 5 render()

The plugin works alongside Craft 5's built-in render() method. While render() looks for templates in _partials/{elementType}/{elementName}.twig, Bonsai Twig provides more sophisticated hierarchical resolution.

Craft 5 render():

Bonsai Twig:

You can use both approaches as needed - render() for simple cases and Bonsai Twig for complex hierarchical template systems.

Development-Only Focus

This plugin is designed specifically as a development tool and includes:

Simplified Architecture

Basic Security

Migration

Upgrading from v8? The v9 breaking changes (underscore path prefixes, plugin handle, config file rename) are covered in MIGRATION.md.

Troubleshooting

Debug Mode Not Working

  1. Ensure devMode = true in your Craft configuration
  2. Check that you're using the correct URL parameter: ?beastmode
  3. Verify the plugin is installed and enabled

Templates Not Found

  1. Use debug mode to see which paths are being checked: ?beastmode
  2. Verify your template directory structure matches the expected hierarchy
  3. Check file permissions on template directories

Template Resolution Issues

  1. Use debug mode to see which paths are being checked: ?beastmode or ?beastmode=entry,matrix
  2. Use the enhanced btPath() function in your templates to see resolution info
  3. Consider simplifying complex template hierarchies

Changelog

See CHANGELOG.md.


All versions of craft-bonsai-twig with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2.0
craftcms/cms Version ^4.4|^5.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 wabisoft/craft-bonsai-twig contains the following files

Loading the files please wait ...