zicht/twig-classes 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

zicht/twig-classes

最新稳定版本:1.1.0

Composer 安装命令:

composer require zicht/twig-classes

包简介

Twig extension for zicht/classes.

关键字:

README 文档

README

Twig extension for zicht/classes.

Installing

composer require zicht/twig-classes

Purpose

Provide easy conditionally joining of CSS classes in Twig templates.

Usage

{{ classes('art-vandelay') }} ⇒ 'art-vandelay'
{{ classes(['art-vandelay', 'kramerica']) }} ⇒ 'art-vandelay  kramerica'
{{ classes(['art-vandelay' => true, 'kramerica' => false]) }} ⇒ 'art-vandelay'
{{ classes('art-vandelay', ['kramerica' => false, 'kel-varnsen' => true]) }} ⇒ 'art-vandelay  kel-varnsen'

Example

When classes are manually added by checking one ore more properties, code can be quite hard to read:

{% set cx = [
    image.url ? 'u-margin--b2' : 'u-margin--b0  u-text--center',
    equal_height  ? 'u-flex'
] %}
   
<article class="{{ cx|join('  ') }}">
    ...
</article>

With the classes function, it becomes much more apparent which class is toggled by what property:

{% set cx = classes({
    'u-margin--b2': image.url,
    'u-margin--b0  u-text--center': not image.url,
    'u-flex': equal_height
}) %} 
   
<article class="{{ cx }}">
    ...
</article>

You can even created a nested object if you need to conditionally apply classes to multiple elements.

{% set cx = {
    card: classes({
        'u-margin--b2': image.url,
        'u-margin--b0  u-text--center': not image.url,
        'u-flex': equal_height
    }),
    img: classes({
        'u-black  u-bg--red': color == 'black'
    })
} %} 
   
<article class="{{ cx.card }}">
    <img class="{{ cx.img }}">
    ...
</article>

统计信息

  • 总下载量: 17.1k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-24