Code Monkey home page Code Monkey logo

twigcsscolorfromstring's Introduction

Symfony Twig Extension CssColorFromString

LICENSE Packagist LICENSE https://jquery.com/

The Twig CssColorFromString bundle extends Twig with a simple filter converting strings to a css color.

Quick Example

<div class="badge" style="color: #222; background-color: {{ tag|hex }};">{{ tag }}</div>

The hex filter converts the tag Standard to the css color #747F3F. The output will be

<div class="badge" style="color: #222; background-color: #747F3F;">Standard</div>

Table of Contents

Getting started

Acknowledgements

Thanks to the stackoverflow developer Reinderien who's post https://stackoverflow.com/a/3724219 is the fundamental of this plugin.

Install via Composer

composer require fincallorca/twig-css-color-from-string "dev-master"

Add Bundle to Symfony Application

Add the CssColorFromStringBundle to app/AppKernel.php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
        
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        return [
            // [...]
            new Fincallorca\TwigExtension\CssColorFromStringBundle\CssColorFromStringBundle(),
        ];
    }
}

Extended Usage

Filter hex

The hex filter converts a string to a css color.

The same string will be converted every time in the same css color (similar like a hash value).

The optional parameter describe the saturation and lightness and can have values between 0 and 1. The example below uses a saturation of 0.5 and a lightness of 0.9. If no parameters are submitted 0.5 is used for each parameter.

<div class="badge" style="color: #222; background-color: {{ tag|hex(0.5, 0.9) }};">{{ tag }}</div>

twigcsscolorfromstring's People

Contributors

prokki avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

seyvillas

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.