Not a pain at all. It can’t be working all the time or you wouldn’t get that error.
It will fail when a page is accessed directly without the user having come from a page with the snippet that sets the variables.
Let’s make one more change:
<?php
/* SetPlaceholders snippet */
if (! empty($_POST['pageId']) ) {
$resource = $modx->getObject('modResource',$_POST['pageId']);
if ($resource) {
$modx->setPlaceholder('MyPagetitle',$resource->get('pagetitle'));
$modx->setPlaceholder('MyLongtitle',$resource->get('longtitle'));
$modx->setPlaceholder('MyContent',$resource->getContent()); // notice this one is a little different
}
}
return '';
That will leave the placeholders empty if the user doesn’t come in from one of your pages.
You may want to use output modifiers to hide the captions if the placeholders are empty.