2017 © Pedro Peláez
 

library twig-sass

A Twig extension/function to render inline SASS files for SEO purposes or to render CSS files with easy customizability

image

richard87/twig-sass

A Twig extension/function to render inline SASS files for SEO purposes or to render CSS files with easy customizability

  • Wednesday, November 16, 2016
  • by Richard87
  • Repository
  • 2 Watchers
  • 5 Stars
  • 106 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 1 % Grown

The README.md

twig-sass

A Twig extension/function to render inline SASS files for SEO purposes. You can also use twig variables inside your sass files., (*1)

Setup:

Add RenderFunction to Twig:, (*2)

$twig = new Twig_Environment(new Twig_Loader_Filesystem());
$renderFunction = new \Richard87\TwigSass\RenderFunction(
    new \Leafo\ScssPhp\Compiler(),
    new Richard87\NullCache\NullCachePool()
    );
$twig->addExtension($renderFunction);

Or if you are using Symfony, add this to services.yml:, (*3)

app.sass_compiler:
    class: Leafo\ScssPhp\Compiler

app.twig.sass_renderer:
    class: Richard87\TwigSass\RenderFunction
    arguments: ['@app.sass_compiler','@cache.app']
    tags:
      - { name: twig.extension}

Options

RenderFunction takes 4 arguments: - Leafo\ScssPhp\Compiler: does the actual compilation of your sass file - PSR6 Cache Pool: A PSR6 enabled Cache pool is requried for any useful performance - importDir: The location SCSS should look for libraries, usually where your node_modules are (mine is in web) - sassFormater: How your output should look like. Takes a classname in string format. Can be any of these values: - "Leafo\ScssPhp\Formatter\Expanded" - "Leafo\ScssPhp\Formatter\Nested" - "Leafo\ScssPhp\Formatter\Compressed" - "Leafo\ScssPhp\Formatter\Compact" - "Leafo\ScssPhp\Formatter\Crunched", (*4)

Usage

Then render inline styles like this:, (*5)

<style>
    {{ renderSass("styles.scss.twig") }}
</style>

styles.scss.twig:, (*6)

$brand-primary: #59cc4a;
$border-radius: 0;
$border-radius-lg: 0;
$border-radius-sm: 0;
@import "node_modules/bootstrap/scss/bootstrap";

Notice that node_modules is inside the web directory, but that can be easily changed with the importRootDir variable., (*7)

You can also use the included renderSass filter like this:, (*8)

<style>
    {{ '$brand-primary: #59cc4a;@import "node_modules/bootstrap/scss/bootstrap";'|renderSass }}
</style>

TODO

  • Create a Symfony hook that automatically renders *.scss.twig templates
  • Write tests

The Versions

16/11 2016

dev-master

9999999-dev

A Twig extension/function to render inline SASS files for SEO purposes or to render CSS files with easy customizability

  Sources   Download

MIT

The Requires

 

by Richard Hagen

twig sass

16/11 2016

1.0.5

1.0.5.0

A Twig extension/function to render inline SASS files for SEO purposes or to render CSS files with easy customizability

  Sources   Download

MIT

The Requires

 

by Richard Hagen

twig sass

16/11 2016

1.0.4

1.0.4.0

A Twig extension/function to render inline SASS files for SEO purposes or to render CSS files with easy customizability

  Sources   Download

MIT

The Requires

 

by Richard Hagen

twig sass

16/11 2016

1.0.2

1.0.2.0

A Twig extension/function to render inline SASS files for SEO purposes or to render CSS files with easy customizability

  Sources   Download

MIT

The Requires

 

by Richard Hagen

twig sass

16/11 2016

1.0.1

1.0.1.0

A Twig extension/function to render inline SASS files for SEO purposes or to render CSS files with easy customizability

  Sources   Download

MIT

The Requires

 

by Richard Hagen

twig sass

16/11 2016

1.0.0

1.0.0.0

A Twig extension/function to render inline SASS files for SEO purposes or to render CSS files with easy customizability

  Sources   Download

MIT

The Requires

 

by Richard Hagen

twig sass