Using latest phpQuery revisions you can easily keep template’s markup and logic in one place with 2 extra lines of code. This heavily breaks the general concept, but it may be useful in some cases. Idea is based on support for callbacks as template sources. First you start dumping markup with 1 line.
<?php ob_start(); ?>
After that the markup goes
<html> <body> <div>Hello world</div> </body> </html>
And at the end there is whole logic. $markup is dumped using new CallbackReturnValue, which takes a variable as parameter. When callback is called it just returns it.
<?php
require('../src/QueryTemplates.php');
$markup = new CallbackReturnValue(ob_get_clean());
require template('test')->parse($markup)
->find('div')
->text('Hello template!')
;
This approach could also be used for getting markup with requestAction in CakePHP views.