While restoring ajax functionality I saw this little big

in the flag.html.twig

As might be expected

{# Attach the flag CSS library.#}
{{ attach_library('flag/flag.link') }}

does not actually ensure that the wanted css appears in the page!

CommentFileSizeAuthor
#2 initial-2848774-2.patch438 bytesmartin107

Comments

martin107 created an issue. See original summary.

martin107’s picture

Title: attach_library is not working. » Within template file attach_library is not working.
StatusFileSize
new438 bytes

Just what to document my thinking ... please note I have not fixed the problem!

I want to fixing this by shoe horning what we have into a form that reflects best practise.

1) From

https://www.drupal.org/docs/develop/standards/css/css-file-organization-...

If a module attaches a CSS file to a template file, the CSS file should be named the same as the template file, e.g. the system-plugin-ui-form.html.twig CSS file should be named system-plugin-ui-form.css

so I have changed the name from flag-line.css to flag.css.

2) Although this module is a relatively simple with regard to theming - I would like to adhere to a semantically meaningful directory structure so I am moving into a subdirectory 'css/component'.

martin107’s picture

I have a update

I am not sure if I am analysing this correctly but

drush en twigc

gives this stack trace... Is the use of attach_library incompatible with lazy loading???

LogicException: Render context is empty, because render() was called outside of a renderRoot() or renderPlain() [error]
call. Use renderPlain()/renderRoot() or #lazy_builder/#pre_render instead. in
/Users/martin/sites/drupal/core/lib/Drupal/Core/Render/Renderer.php:241
Stack trace:
#0 /Users/martin/sites/drupal/core/lib/Drupal/Core/Render/Renderer.php(195):
Drupal\Core\Render\Renderer->doRender(Array, false)
#1 /Users/martin/sites/drupal/core/lib/Drupal/Core/Template/TwigExtension.php(380):
Drupal\Core\Render\Renderer->render(Array)
#2
/Users/martin/sites/drupal/sites/default/files/php/twig/58bda4ba21ca5_flag.html.twig_5hBpUW_ajeUVKzDlPDuY_Z_yw/gPbMZH_AQh4aly8xqsVKj-fryixZqSFwXoZOjybPDrU.php(45):
Drupal\Core\Template\TwigExtension->attachLibrary('flag/flag.link')
#3 /Users/martin/sites/drupal/vendor/twig/twig/lib/Twig/Template.php(432):
__TwigTemplate_7085c4f0fdae9f4e651c2b7bee4e3f80fa5417b808538eae7bf23aed4e72bbcd->doDisplay(Array, Array)
#4 /Users/martin/sites/drupal/vendor/twig/twig/lib/Twig/Template.php(403):
Twig_Template->displayWithErrorHandling(Array, Array)
#5 /Users/martin/sites/drupal/vendor/twig/twig/lib/Twig/Template.php(411): Twig_Template->display(Array)
#6 /Users/martin/sites/drupal/core/themes/engines/twig/twig.engine(64): Twig_Template->render(Array)
#7 /Users/martin/.composer/vendor/drush/drush/commands/core/core.drush.inc(1368):
twig_render_template('modules/flag/te...', Array)
#8 /Users/martin/.composer/vendor/drush/drush/includes/command.inc(422): drush_core_twig_compile()
#9 /Users/martin/.composer/vendor/drush/drush/includes/command.inc(231): _drush_invoke_hooks(Array, Array)
#10 /Users/martin/.composer/vendor/drush/drush/includes/command.inc(199): drush_command()
#11 /Users/martin/.composer/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch(Array)
#12 /Users/martin/.composer/vendor/drush/drush/includes/preflight.inc(66):
Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#13 /Users/martin/.composer/vendor/drush/drush/drush.php(12): drush_main()
#14 {main}

martin107’s picture

Status: Active » Closed (cannot reproduce)

Maybe core has been fixed since this issue was created.