PHPackages                             viget/craft-classnames - 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. viget/craft-classnames

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

viget/craft-classnames
======================

Classnames plugin for Craft CMS

3.0.0(2y ago)1115.5k[1 PRs](https://github.com/vigetlabs/craft-classnames/pulls)1MITPHPPHP ^8.2

Since Sep 16Pushed 2y ago14 watchersCompare

[ Source](https://github.com/vigetlabs/craft-classnames)[ Packagist](https://packagist.org/packages/viget/craft-classnames)[ RSS](/packages/viget-craft-classnames/feed)WikiDiscussions v3 Synced 1w ago

READMEChangelog (7)Dependencies (4)Versions (12)Used By (1)

[![](resources/icon.png)](resources/icon.png)

Classnames plugin for Craft CMS 5.x
===================================

[](#classnames-plugin-for-craft-cms-5x)

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.

This plugin is especially useful with Tailwind CSS projects.

Requirements
------------

[](#requirements)

This plugin requires Craft CMS 5.0.0 or later.

For Craft 4 users, [view the v2 branch](https://github.com/vigetlabs/craft-classnames/tree/v2).

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

[](#installation)

To install the plugin, follow these instructions.

1. Open your terminal and go to your Craft project:

    ```
     cd /path/to/project

    ```
2. Then tell Composer to load the plugin:

    ```
     composer require viget/craft-classnames

    ```
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.

Using Classnames
----------------

[](#using-classnames)

A real world example:

```

  {{ props.text }}

```

Other examples:

```
{{ classNames('foo', 'bar') }} {# 'foo bar' #}
{{ classNames('foo', { 'bar': true }) }} {# 'foo bar' #}
{{ classNames({ 'foo-bar': true }) }} {# 'foo-bar' #}
{{ classNames({ 'foo-bar': false }) }} {# '' #}
{{ classNames({ 'foo': true }, { 'bar': true }) }} {# 'foo bar' #}
{{ classNames({ 'foo': true, 'bar': true }) }} {# 'foo bar' #}
```

There is even a shorthand `cx` version available:

```
{{ cx('foo', { 'bar': true }) }} {# 'foo bar' #}
```

---

[ ![Code At Viget](https://camo.githubusercontent.com/93b8927421fe8b33578eb274ce1d4b71954df6f83e2b0e51c28d92e8ac64d6ac/687474703a2f2f636f64652e76696765742e636f6d2f6769746875622d62616e6e65722e706e67)](http://code.viget.com)Visit [code.viget.com](http://code.viget.com) to see more projects from [Viget](https://viget.com).

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~184 days

Recently: every ~92 days

Total

10

Last Release

780d ago

Major Versions

v1.x-dev → 2.0.02023-03-27

v2.x-dev → v3.x-dev2024-03-29

PHP version history (2 changes)2.0.0PHP ^8.0.2

3.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/9728af4299f2de6d5f099f957bf6f4c8b312076b104910f8d4d8afc39540b686?d=identicon)[viget](/maintainers/viget)

---

Top Contributors

[![jeremyfrank](https://avatars.githubusercontent.com/u/283397?v=4)](https://github.com/jeremyfrank "jeremyfrank (14 commits)")[![joshuapease](https://avatars.githubusercontent.com/u/2145998?v=4)](https://github.com/joshuapease "joshuapease (11 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (6 commits)")[![olets](https://avatars.githubusercontent.com/u/3282350?v=4)](https://github.com/olets "olets (1 commits)")

---

Tags

craft-plugincraft3craft4craft5tailwindcsstwigcsscmstailwindCraftcraftcmscraft-pluginclassnames

### Embed Badge

![Health badge](/badges/viget-craft-classnames/health.svg)

```
[![Health](https://phpackages.com/badges/viget-craft-classnames/health.svg)](https://phpackages.com/packages/viget-craft-classnames)
```

###  Alternatives

[wbrowar/guide

A CMS Guide for Craft CMS.

6154.5k1](/packages/wbrowar-guide)[jalendport/craft-preparse

A fieldtype that parses Twig when an element is saved and saves the result as plain text.

1086.4k](/packages/jalendport-craft-preparse)[nystudio107/craft-autocomplete

Provides Twig template IDE autocomplete of Craft CMS &amp; plugin variables

44204.4k13](/packages/nystudio107-craft-autocomplete)[verbb/footnotes

Adds a footnotes feature to CKEditor fields and Twig templates.

213.3k](/packages/verbb-footnotes)

PHPackages © 2026

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