hello,
I’m making a Snippet that depends on javascript, and I’d like to have one of my snippet parameters to edit some js file.
I was wondering what’s the best way to do it ? (I mean performance/User-friendly -- for people who need to work with this snippet)
I tought :
1) Make a js document in modx doc tree, opening it in my snippet with $jsDoc = $modx->getDocumentObject(’id’,id_of_my_js_file); and then editing the $jsDoc[’content’]
2) Make a chunk with the script content, either editing it with the $modx->getChunk(’jschunk’); or parsing it with $modx->parseChunk(’jschunk’, $array_of_parameters, ’[+’, ’+]’);
(of course, my js content will have placeholders like [+some_parameter+] )
3) Include a JS file from the file system, and editing with php.
I think the Chunk method could be more performant, am I right ? Maybe you have another solution ?
In fact, none of the ideas you have can fit :
The JS ’file’ has to correspond to a custom user chunk (the user should edit it, so It should edit the JS), so I can’t generate it.
But I’d like my users could easily switch some parts of the JS, and that could be done only (I think) with a Snippet Parameter.
That’s why my snippet has to manipulate the JS file. I’ll show an exemple as soon as possible.
Can you give the users specific choices, or as an alternative, let them fill in specific fields that would alter the js behavior or do they really need to edit the js themselves? Letting users edit raw js seems like a *huge* security risk.
Bob
There’s probably a more elegant and easier

way, but the first thing that comes to mind is a form that posts to itself and, on post-back, saves the data in SESSION variables and sends the user to another page where your snippet is. The snippet gets the data and outputs the JS on the fly.
Bob