Try our conversational search powered by Generative AI!

Puttings styles in head for blocks



I am wondering if it's possible to render

Jun 30, 2017 10:23

MVC Section can be your friend.


Jun 30, 2017 11:11

But that doesn't work for blocks

Jun 30, 2017 11:18

(Generally speaing, Blocks is a resuable component, Ideally, should not be used to render scripts)

If I am understanding it correctly, you will require to create a flag at rootlayout level to decide rather to render particular style or not rather at Block level. 

Jun 30, 2017 11:25

Please see But instead of using .AtFooter(), use .AtHeader(). Also use RequireStyle instead of RequireScript.

Edited, Jun 30, 2017 13:48

@Johan Cool, I have never tried this for blocks before as I probably have missed your blog :), just wondering, If its a collection of blocks on a page? will that script be included mutiple times?


Jun 30, 2017 13:55

You have not missed it, since you actually commented on it :)

No it will only be added once. You can also set up dependencies, so it's added before another resource and that they're added as well.

Jun 30, 2017 14:02

This worked perfectly, thanks Johan!

Jul 03, 2017 10:46
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.