Simpods MVC allows for the ability to automatically enqueue scripts for your pages without you having to enqueue them yourself. In order to utilise this functionality, your scripts need to meet the following criteria;
- The file needs to be named the same as your template
- e.g. “front-page.php” would have a script called “front-page.js”
- The file is located in the same place relative to the theme within the “mvc/js” folder
- e.g. “template/template-about.php” would have a script located in “mvc/js/template/template-about.js”
- The file needs to be named the same as the current page.
- The rule is that if it is a post type, it will be post_type.php; if not and the variable “page” exists in the url, it will be $_GET[‘page’].php; else, it will just use the request script name, e.g. script.php
- e.g. “script.php” would have a script called “script.js”
- The file is located in the same place relative to the theme within the “mvc/admin/js” folder
- e.g. “page” post type would have a script located in “mvc/admin/js/page.js”
If your script follows the above criteria, your script should be automatically enqueued into the page. The handle will be the file name with the ending
min.js or .js replaced with
If the page script depends on any libraries these will need to be enqueued manually using the controller’s
This methods accepts an associative array where the keys are script handles and values are file paths relative to the theme. Note that a
-js suffix will be appended to the handle if it is not already present.
In this example the page script depends on Shuffle which has been saved under the library folder structure. The following code should be placed within the page controller’s