├── .gitignore
├── CHANGELOG.md
├── LICENSE.md
├── README.md
├── composer.json
├── composer.lock
├── phpstan.neon
├── resources
└── icon.png
└── src
├── Classnames.php
├── icon.svg
├── translations
└── en
│ └── classnames.php
└── twigextensions
└── ClassnamesTwigExtension.php
/.gitignore:
--------------------------------------------------------------------------------
1 | # CRAFT ENVIRONMENT
2 | .env.php
3 | .env.sh
4 | .env
5 |
6 | # COMPOSER
7 | /vendor
8 |
9 | # BUILD FILES
10 | /bower_components/*
11 | /node_modules/*
12 | /build/*
13 | /yarn-error.log
14 |
15 | # MISC FILES
16 | .cache
17 | .DS_Store
18 | .idea
19 | .project
20 | .settings
21 | *.esproj
22 | *.sublime-workspace
23 | *.sublime-project
24 | *.tmproj
25 | *.tmproject
26 | .vscode/*
27 | !.vscode/settings.json
28 | !.vscode/tasks.json
29 | !.vscode/launch.json
30 | !.vscode/extensions.json
31 | config.codekit3
32 | prepros-6.config
33 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Classnames Changelog
2 |
3 | All notable changes to this project will be documented in this file.
4 |
5 | The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
6 |
7 | ## 2.0.1 - 2023-08-09
8 | ### Changed
9 | - Update plugin author name
10 |
11 | ### Fixed
12 | - Fixed plugin icon not showing up in the CP
13 |
14 | ## 2.0.0 - 2022-08-18
15 | ### Added
16 | - Initial Craft CMS 4 release
17 |
18 | ## 1.0.3 - 2021-02-15
19 | ### Changed
20 | - Updated install instructions with new `plugin/install` command for Craft 3.5
21 |
22 | ## 1.0.2 - 2020-04-09
23 | ### Changed
24 | - Move icons
25 |
26 | ## 1.0.1 - 2020-03-18
27 | ### Added
28 | - Plugin icon
29 |
30 | ## 1.0.0 - 2019-09-16
31 | ### Added
32 | - Initial release
33 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2022 Viget Labs
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Classnames plugin for Craft CMS 5.x
4 |
5 | Classnames is a simple Twig function for conditionally joining css class names together in Twig templates, in a way that makes them much more readable. It's like Jed Watson's [Classnames](https://github.com/JedWatson/classnames) but for Twig in Craft.
6 |
7 | This plugin is especially useful with Tailwind CSS projects.
8 |
9 | ## Requirements
10 |
11 | This plugin requires Craft CMS 5.0.0 or later.
12 |
13 | For Craft 4 users, [view the v2 branch](https://github.com/vigetlabs/craft-classnames/tree/v2).
14 |
15 | ## Installation
16 |
17 | To install the plugin, follow these instructions.
18 |
19 | 1. Open your terminal and go to your Craft project:
20 |
21 | cd /path/to/project
22 |
23 | 2. Then tell Composer to load the plugin:
24 |
25 | composer require viget/craft-classnames
26 |
27 | 3. Install the plugin either via the CLI with `./craft plugin/install classnames`, or in the Control Panel by going to Settings → Plugins and clicking the “Install” button for Classnames.
28 |
29 | ## Using Classnames
30 |
31 | A real world example:
32 |
33 | ```twig
34 |
46 | ```
47 |
48 | Other examples:
49 |
50 | ```twig
51 | {{ classNames('foo', 'bar') }} {# 'foo bar' #}
52 | {{ classNames('foo', { 'bar': true }) }} {# 'foo bar' #}
53 | {{ classNames({ 'foo-bar': true }) }} {# 'foo-bar' #}
54 | {{ classNames({ 'foo-bar': false }) }} {# '' #}
55 | {{ classNames({ 'foo': true }, { 'bar': true }) }} {# 'foo bar' #}
56 | {{ classNames({ 'foo': true, 'bar': true }) }} {# 'foo bar' #}
57 | ```
58 |
59 | There is even a shorthand `cx` version available:
60 |
61 | ```twig
62 | {{ cx('foo', { 'bar': true }) }} {# 'foo bar' #}
63 | ```
64 |
65 | ***
66 |
67 |
68 |
69 |
70 |
71 | Visit [code.viget.com](http://code.viget.com) to see more projects from [Viget](https://viget.com).
72 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "viget/craft-classnames",
3 | "description": "Classnames plugin for Craft CMS",
4 | "type": "craft-plugin",
5 | "version": "3.0.0",
6 | "keywords": [
7 | "craft",
8 | "cms",
9 | "craftcms",
10 | "craft-plugin",
11 | "classnames",
12 | "tailwind",
13 | "css",
14 | "twig"
15 | ],
16 | "support": {
17 | "docs": "https://github.com/vigetlabs/craft-classnames/blob/v2/README.md",
18 | "issues": "https://github.com/vigetlabs/craft-classnames/issues"
19 | },
20 | "license": "MIT",
21 | "authors": [
22 | {
23 | "name": "Viget",
24 | "homepage": "https://www.viget.com/"
25 | }
26 | ],
27 | "require": {
28 | "php": "^8.2",
29 | "craftcms/cms": "^5.0.0",
30 | "newridetech/php-classnames": "^1.2"
31 | },
32 | "autoload": {
33 | "psr-4": {
34 | "viget\\classnames\\": "src/"
35 | }
36 | },
37 | "extra": {
38 | "name": "Classnames",
39 | "handle": "classnames",
40 | "hasCpSettings": false,
41 | "hasCpSection": false,
42 | "changelogUrl": "https://raw.githubusercontent.com/vigetlabs/craft-classnames/v2/CHANGELOG.md",
43 | "class": "viget\\classnames\\Classnames"
44 | },
45 | "config": {
46 | "allow-plugins": {
47 | "yiisoft/yii2-composer": true,
48 | "craftcms/plugin-installer": true
49 | },
50 | "optimize-autoloader": true,
51 | "sort-packages": true
52 | },
53 | "minimum-stability": "dev",
54 | "prefer-stable": true,
55 | "require-dev": {
56 | "craftcms/phpstan": "dev-main",
57 | "craftcms/rector": "dev-main"
58 | },
59 | "scripts": {
60 | "phpstan": "phpstan --memory-limit=1G"
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/phpstan.neon:
--------------------------------------------------------------------------------
1 | includes:
2 | - vendor/craftcms/phpstan/phpstan.neon
3 |
4 | parameters:
5 | level: 9
6 | paths:
7 | - src
--------------------------------------------------------------------------------
/resources/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vigetlabs/craft-classnames/4df921789c21ffb7a2a9e4c8e9af87391f5c9095/resources/icon.png
--------------------------------------------------------------------------------
/src/Classnames.php:
--------------------------------------------------------------------------------
1 | view->registerTwigExtension(new ClassnamesTwigExtension());
54 |
55 | Craft::info(
56 | Craft::t(
57 | 'classnames',
58 | '{name} plugin loaded',
59 | ['name' => $this->name]
60 | ),
61 | __METHOD__
62 | );
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/icon.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/translations/en/classnames.php:
--------------------------------------------------------------------------------
1 | 'Classnames plugin loaded',
16 | ];
17 |
--------------------------------------------------------------------------------
/src/twigextensions/ClassnamesTwigExtension.php:
--------------------------------------------------------------------------------
1 |