cambis / silverstripe-classnames
Classnames package for Silverstripe.
v0.1.1
2023-09-16 03:10 UTC
Requires
- php: ^7.4 || ^8.0
- newridetech/php-classnames: ^1.2
- silverstripe/framework: ^4.0 || ^5.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.7
README
This package is a Silverstripe port of php-classnames.
Getting started
Install the package via composer.
composer require cambis/silverstripe-classnames
Usage
This package provides the $Cn
method for use Silverstripe templates.
Arguments must be parsed as a JSON encoded array.
One way to accomplish this is to create a function that returns the appropriate encoded values,
i.e. getClassnames()
.
<?php use JsonSerializable; use SilverStripe\ORM\DataObject; class MyObject extends DataObject implements JsonSerializable { public function getClassnames(): string { return json_encode($this); } public function jsonSerialize(): mixed { return [ ['foo' => true], 'bar', ]; } }
Then call the function in your template file.
<!-- MyObject.ss --> <p class="{$Cn($Classnames)}">Classnames</p>