Page 1 of 1

Global JavaScript Object for CMS Made Simple

Posted: Wed Dec 17, 2014 10:29 pm
by bbonora
I'm interested in creating a module that will allow other modules to send JavaScript to page templates. The module would be a tag at the bottom of the page and would combine, minify and cache all the JS into a single file at the bottom of the page and eliminate all the inline JS that occurs now.

Both WordPress and Drupal already have system to handle Plugin/Module JS and I was wondering if anybody had any feedback on a good way to implement this into CMS Made Simple. I have couple of ideas but am interested in what the group thinks.

Re: Global JavaScript Object for CMS Made Simple

Posted: Mon Jan 05, 2015 9:13 pm
by psy
You can achieve what you want with smarty template code.

Eg, in a module template (assumes CGExtensions is installed for {jsmin} but you can assign any tag):

Code: Select all

{jsmin assign='js'}
{literal}
<__script__>
$(document).ready(function()({
...
});
</__script>
{/literal}
{append var=pagejs value=$js}
Then in your page template immediately above the <__body> tag:

Code: Select all

<__script__ src="source/to/jquery"></__script>
{if is_array($pagejs)}
{foreach from=$pagejs item=js}
{$js}
{/foreach}
{/if}
Vars from the module template are then included in the javascript before it gets sent to the bottom of the page.

See http://forum.cmsmadesimple.org/viewtopi ... =4&t=70092 for more info.

Rolf also has a great solution to combine scripts into one page. See https://www.cmscanbesimple.org/blog/eas ... s-and-code

hth
psy