Closed bigbigant closed 9 years ago
like this
/**
*<html>
*Hello {{$name}}
* </html>
*/
use Tage\Runtime;
//_Templatexxx = _Template + md5(viewpath)
class _Templatexxx extends AbstractTemplate
{
public function render($vars){
echo "<html>\n";
echo "Hello ";
echo "$vars['name']";
echo "</html>";
}
}
~
There're 3 small problems.
1.For compatibility with the old versions, a template have to use multiple variables. e.g.
<title>{{$api.current.doc.title|escape}} - {{$params.siteName|escape}}</title>
So I suppose there must be an extract($vars) action in render().
2.for compatibility with the old versions, again, a template mustn't under the namespace Tage\Runtime.
Sometimes, the system functions would be invoked directly without a \
.
So we have to make sure that the main rendering blocks run under global namespace.
3.As a performance consideration, to use static method is better, I guess.
$api.current
as safeGet($vars['api'],"current")
.But we need to support the mixin php code,they can't easy to change,so I agree to extract $vars.The change version may be like this?
/**
*<html>
*Hello {{$name}}
* </html>
*/
use Tage\Runtime;
//_Templatexxx = _Template + md5(viewpath)
class _Templatexxx extends AbstractTemplate
{
public function render($vars){
extract($vars);
echo "<html>\n";
echo "Hello ";
echo "$name";
echo "</html>";
}
}
OK. I think we have reached an agreement on the 1st and 3rd. As for the 2nd, no need to move the AbstractTemplate. Just address the Compiled classes under Global. Like this:
<?php
/**
*<html>
*Hello {{$name}}
* </html>
*/
use Tage\Runtime\AbstractTemplate;
//_Templatexxx = _Template + md5(viewpath)
class _Tage_Compiled_Template_Xxx extends AbstractTemplate
{
public function render($vars){
extract($vars);
echo "<html>\n";
echo "Hello ";
echo "$name";
echo "</html>";
}
}
After all the compiled classes are not common, they wouldn't be loaded by any autoloader.
Update the sample:
use Tage\Runtime\AbstractTemplate;
class _Tage_Compiled_Template_c21f969b5f03d33d43e04f8f136e7682 extends AbstractTemplate
{
public function render($vars){
extract($vars);
echo <<<'TEXT'
<html>
Hello
TEXT;
echo ($name);
echo <<<'TEXT'
</html>
TEXT;
}
}
I've to decide how to load compiled script now.