0

I am using Evolution CMS (Modx) and have several functions declared (in snippets).

Those functions I can include in Evo CMS by calling e.g. $modx->runSnippet('functions_main');.

Now I have an external PHP script (independent from Evo CMS) and would like to use those functions there.

However, I don't know how to properly access them (from the DB) and integrate them as PHP functions.

I thought of building my own version of evalSnippet() (Core.php) but could not get it done yet.


I would need something like include_modx_snippet('functions_main'); which reads the snippet (the defined functions) from the DB and makes them available as PHP functions.


Or I just find out how to parse the snippet content and turn it into PHP functions.

Avatar
  • 14,622
  • 9
  • 119
  • 198
  • What EVO version do you use? There is API implementation attempt, see this doc please https://docs.evo.im/04_extras/doclister/09_modxapi.html (sorry but Russian documentation only, please let me know if you need help with translation), this is how you can use this externally. This is how you could use it externally: include_once(MODX_BASE_PATH. "assets/lib/MODxAPI/modSnippet.php"); Unfortunately modSnippet has not much useful but maybe you can use your task using modResource, there are useful methods inside. – Anton Tarasov Feb 20 '22 at 16:50
  • Thanks. It is Evo CMS 2.0.4. – Avatar Feb 20 '22 at 17:08
  • For 2.0.4 API presents: https://github.com/evolution-cms/evolution/tree/2.0.x/assets/lib/MODxAPI – Anton Tarasov Feb 21 '22 at 06:37

1 Answers1

0

You can do this by first initialising Modx and then running your snippet like you would normally:

// Modx init
require_once 'config.core.php';
require_once MODX_CORE_PATH.'model/modx/modx.class.php';
$modx = new modX();
$modx->initialize('mgr');

// Run snippet
$modx->runSnippet('functions_main');

// Run your functions here
Bram Verstraten
  • 1,414
  • 11
  • 24