Thanks! I think I get the picture...
You’ve been a big help... again!
MODx Revolution / MAMP / OS X
Did some more digging around on how to get that $_SESSION variable into my Javascript environment. Found two options:
1: Via a JSON encode:
<?php
return json_encode($_SESSION['msg']);
....
2. Via an AJAX call:
Javascript side:
$.ajax({
url: "test.php",
cache: false,
success: function(html){
eval( html );
}
});
PHP side test.php:
echo 'var myData = "'. $_SESSION['msg'].'"';
Any opinions on this? Are both applicable to MODx manager environment?
MODx Revolution / MAMP / OS X
I recommend never using eval.
That said, how I’d do it is in my controller, I’d use $modx->regClientStartupHTMLBlock before instantiating my JS object:
$content = $_SESSION[’msg’];
$modx->regClientStartupHTMLBlock(’<script type="text/javascript">
var Tarriffs.currentContent = "’.$content.’";
</script>’);
And then reference Tarriffs.currentContent in my JS config in the panel.
Note: you might need to escape apostrophes in your $content var.
shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect |
github |
splittingred.com
Ahh.....

Excellent tip!
Thanks!
MODx Revolution / MAMP / OS X