wabisoft / craft-bonsai-twig
Internal use template helper
Installs: 179
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:craft-plugin
Requires
- php: >=8.0.2
- craftcms/cms: ^5.0.0
Requires (Dev)
- craftcms/ecs: dev-main
- craftcms/phpstan: dev-main
- marcocesarato/php-conventional-changelog: ^1.16
README
Welcome to the Twig Template Code Helper Plugin README! This plugin is designed to streamline your Twig templating experience by loading code based on specific element types in Craft CMS 5.
Features
- Automatic Template Loading: Load templates for various element types such as entries, categories, assets, users, and matrix rows.
- Parameter Support: Optional parameters for enhanced debugging during development.
Usage Guide
Core Template Functions
-
Item Templates
- Function:
itemTemplates
- Usage:
{{ itemTemplates({ entry }) }}
- Description: Loops through nested entries.
- Function:
-
Entry Templates
- Function:
entryTemplates
- Usage:
{{ entryTemplates({ entry }) }}
- Description: Loads templates for core entry elements.
- Function:
-
Category Templates
- Function:
categoryTemplates
- Usage:
{{ categoryTemplates({ entry }) }}
- Description: Loads templates for category elements.
- Function:
-
Matrix Templates
- Function:
matrixTemplates
- Usage:
{{ matrixTemplates({ matrix }) }}
- Description: Loads templates for matrix rows.
- Function:
Parameters
Enhance your debugging with the following optional parameters in devMode:
-
showPathParam
- Usage:
{{ entryTemplates({ entry, showPathParam: true }) }}
- Description: Displays the path of the template being rendered.
- Usage:
-
showHierarchyParam
- Usage:
{{ entryTemplates({ entry, showHierarchyParam: true }) }}
- Description: Shows the hierarchy of the template being rendered.
- Usage:
Notes on Craft CMS 5
In Craft CMS 5, categories and matrix elements are now treated as entries and follow the entry model. This unification simplifies template handling and ensures consistency across different element types.
Example Usages
Basic Usage
{{ itemTemplates({ entry }) }} ```twig {{ matrixTemplates({ matrix }) }} ### Advanced Usage Append URL paramters to the URL to render debug info while in devMode ?showPathParam=true&showHierarchyParam=true