I would like to include wayfinder within an external php app, how do I include MODX Revo data within my external php files?
Thanks for the link. I have installed the Bob Ray code but I am still unable to get a chunk containing a snippet call to display. How do I programmatically include a snippet within an external PHP file.
You can call the snippet directly, like this:
$output = '';
$properties = array(
'tpl' => 'MyTplChunk',
'rowTpl' => 'SomeOtherChunk',
);
$output .= $modx->runSnippet('SnippetName', $properties);
I think you can also get the chunk, and then process it like this:
$output = '';
/* The second argument is optional, it lets you set placeholders */
$chunk = modx->getChunk('someChunk', $fields);
$output .= $chunk->process();
Hi Bob,
I have inserted the following code but it seems to fail when calling a snippet;
include $_SERVER['DOCUMENT_ROOT'] . '/assets/components/external/runExternal.php';
$wfOutput = '';
$properties = array(
"startId" => "0",
"level" => "2",
"outerClass" => "nav navbar-nav",
"rowTpl" => "rowMainTpl",
"parentRowTpl" => "parentRowMainTpl",
"parentClass" => "dropdown",
"innerClass" => "dropdown-menu",
);
$wfOutput .= $modx->runSnippet('Wayfinder', $properties);
<?php
/* Assume these are false until we know otherwise */
$cliMode = false;
$outsideModx = false;
/* Set a user (set to an actual username) */
$myUserName = 'admin';
/* Instantiate MODX if necessary */
if (!isset($modx)) {
$outsideModx = true;
/* Set path to MODX core directory */
if (!defined('MODX_CORE_PATH')) {
/* be sure this has a trailing slash */
define('MODX_CORE_PATH', '/var/www/vhosts/domain.com/httpdocs/core/');
}
/* get the MODX class file */
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
/* instantiate the $modx object */
$modx = new modX();
if ((!$modx) || (!$modx instanceof modX)) {
echo 'Could not create MODX class';
}
/* initialize MODX and set current context */
$modx->initialize('web');
// or $modx->initialize('mgr');
/* load the error handler */
$modx->getService('error', 'error.modError', '', '');
/* Set up logging */
$modx->setLogLevel(xPDO::LOG_LEVEL_INFO);
/* Check for CLI mode and set log target */
if (php_sapi_name() == 'cli') {
$cliMode = true;
$modx->setLogTarget('ECHO');
} else {
$modx->setLogTarget('HTML');
}
/* Set $modx->resource, request, and $modx->user */
/* Make sure there's a request */
$modx->getRequest();
/* Set $modx->resource to home page */
$homeId = $modx->getOption('site_start');
$homeResource = $modx->getObject('modResource', $homeId);
if ($homeResource instanceof modResource) {
$modx->resource = $homeResource;
} else {
die('No Resource');
}
/* set $modx->user */
$myUser = $modx->getObject('modUser', array('username' => $myUserName));
if ($myUser instanceof modUser) {
$modx->user = $myUser;
} else {
die('No User');
}
}
?>
running wayfinder outside a frontend-page is another story.
first try to run a simple snippet.
Rethinking the issue. I have decided to using the following php:
<?php echo file_get_contents('http://www.domain.com/PathToWayfinderOutput.html'); ?>
I now add my Wayfinder Snippet to a Chunk and add it to my normal pages and a new "blank" template page.