SCSS/LESS Editor Field

psaunders - 4 weeks ago

I have a custom LESS field attached to post to push out to the front end. How do you get the code to actually be processed so that it can either be added to a bundle, or, parsed inline in a twig file.

    {{ post.style.parse }}
    {{ post.style|raw }}
    {{ post.style.render }} // 500s hunting for some file

The obvious ones above don't work

Answer

- 3 weeks ago

You'll need to add it to an asset collection so use the EditorFieldTypePresenter class in the editor field type to get the path to add to an asset collection:

{{ asset_add('styles.css', post.style.path) }}

piterden - 3 weeks ago

What do you have in output?

psaunders - 3 weeks ago

It just renders it out with no preprocessing so:

.thing{
    .stuff{
    }
}

Comes out instead

piterden - 3 weeks ago

You could add it to assets. Try to play with Assetic. Look at StreamsPlugin class to see what functions of Assetic available inside twig.

ryanthompson - 3 weeks ago

You'll need to add it to an asset collection so use the EditorFieldTypePresenter class in the editor field type to get the path to add to an asset collection:

{{ asset_add('styles.css', post.style.path) }}