Hi
There's already a php function that does what you need (creating escaped query strings from "raw" strings):
http://php.net/manual/de/function.http-build-query.php
or for just single values:
http://php.net/manual/en/function.urlencode.php
As for your problem: Yes, that doesn't work. The template engine isn't that smart. It can't correctly parse $queryEscape to a function and then pass the parsed value of $title as parameter in there.
What you could do is mess around with PHPs magic "__get" method to automatically convert fields to url-encoded strings when they are prefixed with a certain string.
Sounds complicated? It isn't. Here's what you do:
Add the following method to the Page_Controller:
public function __get($field){
// prefix for queries
$key = 'query_';
$len = strlen($key);
if(substr($field, 0, $len) === $key){
$f = substr($field, $len);
$value = parent::__get($f);
return urlencode($value);
}
return parent::__get($field);
}
Now you can output a escaped query string in your template like so:
$query_Title
$query_Content
... etc ...
If you're wondering why/how this works, read this: http://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members