Inline all scripts in asset_scripts(..) instead of echo script tags
Created 10 months ago by finnito

Hey all,

I want to use the asset_inline() Twig command to inline all the scripts contained inside the asset_scripts() collection but can't quite figure out the syntax.

In the docs they give the following syntax to loop through all the scripts in the collection:

{% for script in asset_scripts("scripts.js") %}
    {{ script|raw }}
{% endfor %}

but I'm not sure how I'd work with this for inlining.

Could anyone provide any hints?

ryanthompson  —  10 months ago

Try using asset_urls in the loop and then asset_inline(url)

Otherwise I can make something for ya 😄

finnito  —  10 months ago

That didn't quite seem to work @ryanthompson - I'd be super stoked if you could whip something up! I'm all about minimising those HTTP requests ;)

ryanthompson  —  10 months ago

Can you whip up a feature request issue? I'll get on it tonight or tomorrow.

finnito  —  10 months ago

I would but I'm not sure how! All I can see on the Git for the streams-platform is pull requests and I don't have a fork to do the comparison with so I can't open anything

ryanthompson  —  10 months ago

Ill write something in shortly (tonight) and ping you.

ryanthompson  —  10 months ago

Have you tried just {{ asset_inline("scripts.js") }}? Don't ask me why I didn't think of that before 😛 But that should suffice.