Hmm. Is there any tutorials how to do this? I dont really have any programming skills, so i dont understand how this hangs together.
Or if you could please explain a little further how your snippet works.
I do not want to use any kind of TV to accomplish this, as it needs to be as simple as possible for the user creating resources.
I have tried creating some templates for a couple of years now, and this is always the point where i scratch everything and just entering the entire html structure per template.
As modx have thousands of users and some must have different javascripts per template, I was hoping if anyone could copy/pase their setup, with template, chunks and snippets so its possible to see how it works.
And thanks for your help, i really appreciate you taking the time to answer.
-
☆ A M B ☆
- 24,524 Posts
Personally, I prefer to keep as much structure as possible in a template so I'm not running all over looking for chunks and what-have-you to try to figure out how my structure is getting generated. But that's a matter of personal preference.
It would depend on exactly what you're doing, but the snippet would generally look like this:
<?php
$tplate = $modx->resource->get('template'); // returns ID of current resource's template
switch ($tplate) {
case 1:
$modx->regClientCSS(" ... path to css file here ... ");
$modx->regClientStartupScript(" ... path to js file here ... ");
$js1 = ' ... javascript to embed here ... ';
$modx->regClientScript($js1);
// anything else you want in the way of specific css or javascript for this template
break;
case 2:
// whatever .css and .js or embedded javascript you want in this template
break;
case ...
}
return;
The snippet could go in the template itself, or in one of its chunks. It could even be made into a plugin, but I prefer to avoid using those unless I'm really interrupting and modifying core MODx processing.
References:
http://bobsguides.com/revolution-objects.html
http://php.net/manual/en/control-structures.switch.php
http://rtfm.modx.com/display/revolution20/modX.regClientCSS
http://rtfm.modx.com/display/revolution20/modX.regClientHTMLBlock
http://rtfm.modx.com/display/revolution20/modX.regClientStartupHTMLBlock
http://rtfm.modx.com/display/revolution20/modX.regClientScript
http://rtfm.modx.com/display/revolution20/modX.regClientStartupScript