PHPackages                             josbeir/cakephp-templater-defaults - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. josbeir/cakephp-templater-defaults

ActiveCakephp-plugin[Templating &amp; Views](/categories/templating)

josbeir/cakephp-templater-defaults
==================================

TemplaterDefaults plugin for CakePHP

0.2.1(7mo ago)0127MITPHPPHP &gt;=8.1CI passing

Since Sep 7Pushed 7mo agoCompare

[ Source](https://github.com/josbeir/cakephp-templater-defaults)[ Packagist](https://packagist.org/packages/josbeir/cakephp-templater-defaults)[ RSS](/packages/josbeir-cakephp-templater-defaults/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (7)Versions (6)Used By (0)

Templater defaults Plugin for CakePHP
=====================================

[](#templater-defaults-plugin-for-cakephp)

[![PHPStan Level 8](https://camo.githubusercontent.com/ff3c7f8c8667ce643f47e74532748f673482a5f95d7d4269f925f2eebbe5117e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230382d627269676874677265656e)](https://github.com/josbeir/cakephp-templater-defaults)[![Build Status](https://github.com/josbeir/cakephp-templater-defaults/actions/workflows/ci.yml/badge.svg)](https://github.com/josbeir/cakephp-latte-view/actions)[![codecov](https://camo.githubusercontent.com/c495516830ece103c32997f0f9e8cb8ed0375d436c29c5d5ed492fdff148d01d/68747470733a2f2f636f6465636f762e696f2f67682f6a6f73626569722f63616b657068702d74656d706c617465722d64656661756c74732f67726170682f62616467652e7376673f746f6b656e3d4559554f3949524d3946)](https://codecov.io/gh/josbeir/cakephp-templater-defaults)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![PHP Version](https://camo.githubusercontent.com/744f8821cc27dec8b0013ade48179731a44eadf4f943e0b1d9ffcb93f80177de/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e322532422d626c75652e737667)](https://www.php.net/releases/8.2/en.php)[![Packagist Downloads](https://camo.githubusercontent.com/3281c2bf423db1b25020b656678bdba988a02cbec1578696901bfe746840a439/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f73626569722f63616b657068702d74656d706c617465722d64656661756c7473)](https://packagist.org/packages/josbeir/cakephp-templater-defaults)

A custom templater for CakePHP that enables you to define default HTML attributes within CakePHP's string template system, making it easier to integrate with your preferred CSS setups and streamline HTML markup generated by helpers.

CakePHP's StringTemplates system does not allow merging attributes set at runtime with attributes defined in the template. This little plugin fixes this problem.

---

Table of Contents
-----------------

[](#table-of-contents)

1. [Features](#features)
2. [Installation](#installation)
3. [Usage](#usage)
4. [Examples](#examples)
5. [Limitations](#limitations)
6. [Contributing](#contributing)
7. [License](#license)

Features
--------

[](#features)

- **Attribute Merging**: Runtime attributes are merged with template defaults, allowing easy extension or override.
- **Attribute Swapping**: Use the `:swap` suffix (e.g. `class:swap`) to completely replace a default attribute value.
- **Works with CakePHP Helpers**: Seamlessly integrates with helpers like `FormHelper` via the `templateClass` option.

Installation
------------

[](#installation)

Install via Composer:

```
composer require josbeir/cakephp-templater-defaults
```

Why
---

[](#why)

Imagine this template defintion for your FormHelper

```
'templates' => [
    'input' => '',
];
```

In many cases you will want to add classes to control the size, width, etc. of those elements. This is not possible in core's `StringTemplate` unless you override the entire template at runtime on a per-element basis.

```
$this->Form->control('field', ['class' => 'extra-class']);
// Renders to

  ...

```

**This is not expected behavior.**

Rather than doing that, this plugin uses a different approach: it merges the existing (default) attributes with ones defined at runtime:

```
$this->Form->control('field', ['class' => 'extra-class']);
// Renders to

  ...

```

Usage
-----

[](#usage)

You can use the custom `StringTemplate` class directly or configure CakePHP helpers (like `FormHelper`) to use it:

In your `AppView.php`, set the `templateClass` option on any helper where you want to use this plugin.

```
use \TemplaterDefaults\View\StringTemplate;

$this->loadHelper('Form', [
    'templateClass' => StringTemplate::class,
]);
```

Examples
--------

[](#examples)

### Attribute Merging

[](#attribute-merging)

Default and runtime classes are merged:

```
// In your template file (e.g. src/Template/Example/index.php)
echo $this->Form->control('field', [
	'type' => 'text',
	'class' => 'runtime',
]);
//
```

### Attribute Swapping

[](#attribute-swapping)

Use `class:swap` to replace the default:

```
echo $this->Form->control('field', [
	'type' => 'text',
	'class:swap' => 'swapped',
]);
//
```

Or removing the default attribute.

```
echo $this->Form->control('field', [
	'type' => 'text',
	'class:swap' => '',
]);

//
```

Limitations
-----------

[](#limitations)

- Default attributes obviously only work on html/xml style templates
- Only the top level element will be populated. Nested elements are ignored.

Contributing
------------

[](#contributing)

Contributions, issues, and feature requests are welcome! Feel free to open a pull request or issue on GitHub. Please follow CakePHP coding standards and ensure all code is properly tested before submitting.

License
-------

[](#license)

[MIT](LICENSE.md)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance62

Regular maintenance activity

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

5

Last Release

238d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2899d7bd057eecff34549480753213e1b19652f7f726db2d971b6b0fa69d4c14?d=identicon)[josbeir](/maintainers/josbeir)

---

Top Contributors

[![josbeir](https://avatars.githubusercontent.com/u/26058?v=4)](https://github.com/josbeir "josbeir (25 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/josbeir-cakephp-templater-defaults/health.svg)

```
[![Health](https://phpackages.com/badges/josbeir-cakephp-templater-defaults/health.svg)](https://phpackages.com/packages/josbeir-cakephp-templater-defaults)
```

###  Alternatives

[friendsofcake/cakephp-csvview

A CSV View class for CakePHP

1762.5M3](/packages/friendsofcake-cakephp-csvview)[wyrihaximus/twig-view

Twig powered View for CakePHP

804.7M1](/packages/wyrihaximus-twig-view)[dereuromark/cakephp-ajax

A CakePHP plugin that makes working with AJAX a piece of cake.

55255.9k1](/packages/dereuromark-cakephp-ajax)[dereuromark/cakephp-feed

A CakePHP plugin containing a RssView to generate RSS feeds.

1353.7k1](/packages/dereuromark-cakephp-feed)[dereuromark/cakephp-meta

A CakePHP plugin for SEO meta tags, OpenGraph and Twitter Cards

1012.9k1](/packages/dereuromark-cakephp-meta)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
