Home > OS >  Why is my inline css filter in my template giving an unknown filter error when I try to email myself
Why is my inline css filter in my template giving an unknown filter error when I try to email myself

Time:10-06

I am a Drupal developer and within my Drupal website, I have created a Newsletter issue called test1 newsletter. Newsletter content

I am using Twig as my template engine and I have applied the Twig file simplenews-newsletter-body--default.html.twig to my test1 newsletter.

I need to put some inline css style in my Twig file. To do this, I followed the instructions given at https://twig.symfony.com/doc/2.x/filters/inline_css.html which told me that I first need to download a couple of libraries: twig/cssinliner-extra and twig/extra-bundle which I did in my terminal (code given below):

composer require twig/cssinliner-extra 
composer require twig/extra-bundle 

This is what my simplenews-newsletter-body--default.html.twig file looks like:

{% apply inline_css %}
<html>
<body>
<div id="email" style="width:600px;margin: auto;background:white;">
  <!-- Header -->
  <table role="presentation" border="0" width="100%" cellspacing="0">
  <tr>
    <td bgcolor="#E2FFF8" align="center" style="color: black;">
      <h1 style="font-size: 52px; margin:0 0 20px 0; font-family:Avenir;"> {{ node.getTitle }}</h1>
    </tr>
      </td>
  </table>
</div>
</body>
</html>
{% endapply %}

When I go to my Drupal site to email myself the test1 newsletter (under the heading "Test email address")Look here

I get an Unknown "inline_css" filter error. This is very weird behavior because I did successfully install the libraries to my Twig directory (from the composer require code given above).

The website encountered an unexpected error. Please try again later.

Twig\Error\SyntaxError: Unknown "inline_css" filter. in Twig\ExpressionParser->getFilterNodeClass()

CodePudding user response:

As noted on the inline_css page, it is not loaded by default.
Luckily for you it seems someone has already made a module called twig_inline_css that seems to do exactly what you want.
Install the module with composer and you should be good to go. Or just copy the small amount of code into your own custom module.

  • Related