D
D
Denis Karakchiev2019-03-06 11:23:55
Twig
Denis Karakchiev, 2019-03-06 11:23:55

How to insert css code from file into Twig template?

Converting .twig files via gulp using gulp-twig. In the template, you need to insert css code from the service.css file into the tag How to do it? I saw advice on stackoverflow, but it didn't work like this:<style></style>

<style>
        {{ source('./_service/service.css') }}
</style>

Outputs in markup
<style>
        Template "./_service/service.css" is not defined.
</style>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2019-03-06
@delphinpro

Write a function for twig. It will simply read and return the contents of the file.
In principle, the regular source() does the same thing, you just pass the wrong path to it.
Pass the base: 'src/twig_tpl' option to the twig() call settings (well, this is the path to the templates) and then specify the paths in the templates from this folder

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question