Your first function is correct. Add parent::onBeforePublish() in there.
function onBeforePublish(){
parent::onBeforePublish();
$xml = $this->renderWith('XML');
file_put_contents('/full/path/to/xml-file.xml', $xml);
}
It should be in the MyPage model. The only issue is 'XML' its looking for a template in the template dir called 'XML.ss'.
Perhaps make a new template call xmlexport.ss inside there you'll need to structure the nodes as you see fit. Then call renderWith('xmlexport')
<!xml>
<% loop stuff %>
$Title
<% end_loop %>
Depending on what you're after you could just serialise the object to xml and write that out http://stackoverflow.com/questions/137021/php-object-as-xml-document
Posted to: How do I use renderWith() outside a controller? | Show Thread | Post Reply