2017 © Pedro Peláez
 

library twig-css-color-from-string

A small twig extension to convert string into css color values

image

fincallorca/twig-css-color-from-string

A small twig extension to convert string into css color values

  • Friday, June 30, 2017
  • by prokki
  • Repository
  • 2 Watchers
  • 2 Stars
  • 69 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 6 % Grown

The README.md

Symfony Twig Extension CssColorFromString

LICENSE Packagist LICENSE https://jquery.com/, (*1)

The Twig CssColorFromString bundle extends Twig with a simple filter converting strings to a css color., (*2)

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, (*3)

<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., (*4)

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

``` php, (*5)

use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Config\Loader\LoaderInterface;, (*6)

class AppKernel extends Kernel { public function registerBundles() { return [ // [...] new Fincallorca\TwigExtension\CssColorFromStringBundle\CssColorFromStringBundle(), ]; } }, (*7)



## 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. ```html <div class="badge" style="color: #222; background-color: {{ tag|hex(0.5, 0.9) }};">{{ tag }}</div>

The Versions

30/06 2017

dev-master

9999999-dev

A small twig extension to convert string into css color values

  Sources   Download

MIT

The Requires

 

by Falko Matthies

twig css filter bundle symfony color

30/06 2017

0.0.1

0.0.1.0

A small twig extension to convert string into css color values

  Sources   Download

MIT

The Requires

 

by Falko Matthies

twig css filter bundle symfony color