-
☆ A M B ☆
- 43 Posts
How can I import variables from one snippet into another?
e.g. I have $variable1 = ’Value1’; in [[MyVariables]] and i want to import this variable into [[MyOtherSnippet]]
-
☆ A M B ☆
- 24,524 Posts
You may simply be able to declare it global; I’m not exactly sure which one or both would you have to declare it global. You can load it into the $_SESSION. You can load it into $_GLOBALS. You can use $mdox->setPlaceholder(’myvar’, ’value’) in the first snippet, and $modx->getPlaceholder(’myvar’) in the second snippet (or use it as a parameter with [+myvar+]). This is MODx. There’s probably a dozen ways you can do that.
On checking it out, it turns out you need to declare it global in both snippets.
for global sitewide-variables I tend to use one modx-resource as ’settings’ where I can set this global vars as TVs.
you can then read them on all places where you need them with
<?php
$settingTVs='variable1,variable2,variable3,variable4';//settingTVs to read
$settingid='99';//resource-ID of setting-resource
$settingTVs=explode(',',$settingTVs);
$tvs=$modx->getTemplateVarOutput($settingTVs,$settingid);
echo '<pre>'.print_r($tvs,1).'</pre>';