Puttings styles in head for blocks

Hi!

I am wondering if it's possible to render

#180118
Jun 30, 2017 10:23

But that doesn't work for blocks

#180124
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. 

#180143
Jun 30, 2017 11:25
Vote:

Please see http://dodavinkeln.se/post/how-to-inject-a-script-for-a-block. But instead of using .AtFooter(), use .AtHeader(). Also use RequireStyle instead of RequireScript.

#180149
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?

/K

#180151
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.

#180154
Jun 30, 2017 14:02

This worked perfectly, thanks Johan!

#180202
Jul 03, 2017 10:46
error 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.