How to make a conditional header for loading JS/CSS files? #617
-
Hi I have used the extension approach, modeled on "Helloworld" extension and have got as far as being able to load a css file into the header. However, there are a lot of css & jss files to add, and so I only want these to load into the header on a condition, either that the shortcut "dataviz" is used on a page or some other trick so that the files don't load into headers on every single page and blog post. I have read some other posts related to this but have not managed to understand if this is actually possible or not and am relative noob in php. Here is my code for what I have done so far:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 18 replies
-
Hi. I realise now that this is not really going to help me as markdown doesn't seem to interpret script tags at all in the body, I thought it would. The datavisualisation packages I am using require pretty complicated blocks of javascript code in the body. I tried this below but it neither loaded a javascript file or interpreted a simple javascript command. I guess I should have understood this from the other similar comments, but unless anyone has a solution that I have completely missed I will have to find another tool or keep the datavisualisations as separate html files loaded in an iframe or simply referred to as separate but complete pages if I continue with Yellow.
|
Beta Was this translation helpful? Give feedback.
-
The question about <script> in body was raised some time ago, see #515 The bottom line is that this is not allowed in Yellow for security reasons. No one prevents you from manually editing the whitelist (adding "script" in |
Beta Was this translation helpful? Give feedback.
-
Well, after a moment of serendipity I came up with the following solution:
I do not know if @markseu is happy with this 😇, because this hack (if it really works well) effectively circumvents the security measure of preventing scripts in body... (For |
Beta Was this translation helpful? Give feedback.
-
i use my own layouts (so they aren't affected by updates)
and the slides "layout" has its own HTML PHP and inline javascript While this is not adding it to the head as requested, you may be able to experiment with using the "layout" check in the "head"
to your page, this solution would keep the code out of the mark-down |
Beta Was this translation helpful? Give feedback.
@jonscrut
i use my own layouts (so they aren't affected by updates)
and i display slides on the home page only...
I use a layout for the home page and use php to include the slides layout
<?php if(($this->yellow->page->get("Layout")) == "home") : echo $this->yellow->layout("slides"); endif; ?>
and the slides "layout" has its own HTML PHP and inline javascript
While this is not adding it to the head as requested, you may be able to experiment with using the "layout" check in the "head"
So that when you want the CSS and JS added to the page you may be able to add...
to your page,
this solution would keep the code out of the mark-down