Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Puttings styles in head for blocks

Vote:
 

Hi!

I am wondering if it's possible to render

#180118
Jun 30, 2017 10:23
Vote:
 
#180123
Jun 30, 2017 11:11
Vote:
 

But that doesn't work for blocks

#180124
Jun 30, 2017 11:18
Vote:
 

(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
Vote:
 

@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
Vote:
 

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
Vote:
 

This worked perfectly, thanks Johan!

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