The documentation and example are a bit sparse but I've made a few custom shortcodes in the past as proof of concept and was wondering: regarding custom shortcodes, if one is pulling in some JavaScript for some reason in a shortcode code, either in:
- the .php file under /mysite/code
- or in the template area
- /mysite/template/<somefile>.ss
- or /themes/__/template/<somefile>.ss
and one puts the shortcode handler either in :
- /mysite/code/Page.php
- or /mysite/code/shortcodes/<some-shortcode.php>
does the JavaScript get loaded for every page on the CMS or only pages that have the shortcodes in the content field?
---
If a custom shortcode (or general page template for that matter) uses a JavaScript library that requires the use inclusion of JQuery, what is the correct way to have JQuery included before that library needs it? Normally I would just include JQuery in the <script> line above the library in question, however I know SilverStripe makes extensive use of JQuery and just adding JQuery above another library will possibly result in a conflict. At the moment, including JQuery in the shortcode controller above the external library seems to work but I get a feeling this is going to break something at some point.
Using:
Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.js');
in the <?php section of the shortcode controller and excluding <script src=...> in the same file pointing to jquery from a CDN however results in things breaking.
as does adding Requirements:: to an init() function for the shortcode handler:
public function init() {
Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.js');
}
---
Lastly, having only used modules but never written one, if one wanted to just put all the shortcodes into a SilverStripe module, is it simply a matter of creating a directory in the docroot like:
/html/shortmodule
and under /shortmodule/code having the handler .php file defined, and the .ss template under /html/shortmodule/template and any custom required JS under /shortmodule/javascript ?
Reading the docs on modules, it looks like any PHP classes & templates there are automatically included.
Is there anything special that would need to be in the /shortmodule/_config.php file other than a <?php and registration code for the shortcode handler?