Have you tryed Var_sump or print_array to see the values returned by getDocument?
Yes. The only HTML is the content field.
Andy
there are several ways to get a parsed document.
One of them which I use to get complete parsed documents for ajax-responds is
$modx->sendRedirect($_POST['docurl']);
or
$url=$modx->makeUrl($id);
$modx->sendRedirect($url);
see also:
http://wiki.modxcms.com/index.php/API:makeUrl
http://wiki.modxcms.com/index.php/API:sendRedirect
Thanks for replying. But I think I didn’t really explain what I am trying to do.
I want to change the content of a document outside of MODx. If you look at the example I gave I am getting the details of a page and changing the content field. Now I want to assemble a completed, parsed page from that hash array, therefore using my new content.
thanks, Andy
can you explain your complete situation and what is the reason for doing that. I’m sure there are better ways to get what you want.
In your example I can see only you want to get the document-array with given ID. Then you want to change the content with "<p>Foo</p>";
And parse this new content????
But where comes the id from? What is a real new example-content? from where do you call this script and so on?
I have a complex external PHP application that I want to make look like my MODx site. However I don’t want to duplicate templates, make the menu static, etc. Instead I want to wrap my external PHP application in HTML generated by MODx. That way I can modify the templates, the sidebar, the menu etc. and it will automatically be updated for the external app.
The MODx API can be accessed from any PHP script simply by including index.php. $modx is then available for use.
Andy
This is what you can do:
<?php
define('MODX_API_MODE', true);
$path = dirname(__FILE__).'/';
include($path.'index.php');
$content='this is my new content';
//$GLOBALS['app_content']=$content;//if you want to replace the content-field with plugin use this
$modx->setPlaceholder('app_content',$content);//if you want replace a placeholder use this
ob_start();
$_REQUEST['id'] = $docid;
$modx->executeParser();
$html = ob_get_contents();
ob_end_clean();
echo $html;
?>
if you want to replace the content field you can do it with this plugin and onParseDocument checked:
if (isset($GLOBALS['app_content'])){
$output= $modx->documentOutput;
$modx->documentOutput = str_replace('[*content*]',$GLOBALS['app_content'], $output);
}
But why not running your application as a modx-snippet?
Quote from: Andy at Jan 25, 2010, 01:33 PM
Hi, I am calling the MODx (Evolution) API from outside MODx. I.e. in a simple PHP script. How can I generate a complete page from the hash array returned by getDocument? For example:
$data = $modx->getDocument($id);
$data["content"] = "<p>Foo</p>";
// what goes here to convert $data to parsed html?
echo $html;
thanks, Andy
Generating a complete page is pretty complicated. It involves getting the document template from the DB and then parsing all the tags in the template (and tags contained in things references by those tags, etc., etc.).
That said, you may find the functions you need in the document parser (although you may want to call getDocumentObject() rather than getDocument()).
manager/includes/document.parser.inc.php