How can an extension put some code just before the closing body tag? #876
-
I have recently written a few simple plugins, just for personal use. One of these plugins, I called it beforeafter, shows two images that you can slide between. An important part for this plugin, a javascript, I found on github in the repo beerslider. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hello! If you are thinking about an extension which adds Javascript code in a page with a shortcut, this is impossible: Javascript code in markdown is filtered out by the core of Yellow for safety reasons (and a shortcut is in Yellow a sort of extension to markdown). If I well remember, in the past there were much heated discussions on this subject. Personally, I agree with this choice of the developers, above all because it helps writing cleaner code. But there are at least two other solutions: Easy, quick and dirty solutionAdd the Javascript code in the template (default.html, or also footer.html). The content of the templates is not filtered, so you can write whatever you wish, wherever you wish. In the case of beerslider the code should do no harm in the pages which do not contain a "slider" id. (This is exactely what you've done.) Edit: see @markseuffert's answer for an example of how to insert some code in the footer without modifying the layouts. The Yellow-style solutionWhen the instructions for a script say "put it just before
This can be the content of a tiny Javascript file, included in the header of the page with Two sidenotes:
|
Beta Was this translation helpful? Give feedback.
-
Example 1 - Extension loads JavaScript in the footer:
Example 2 - Extension loads JavaScript in the header:
The second example is how most extensions work. If a library requires you to execute code, then put the JavaScript code into the JavaScript file and use |
Beta Was this translation helpful? Give feedback.
Example 1 - Extension loads JavaScript in the footer: