haXe Forum > Trouble with templo's "use"
-
Nick Sabalausky Feb 06 at 23:20
I'm using the templo tool/lib (v2.3.1) in optimized mode, and I'm having trouble with "use".
Here's the files in my sample test app:
Main.hx:
// Test templo import php.Web; import templo.Loader; class Main { public static function main() { Loader.OPTIMIZED = true; Loader.MACROS = null; Loader.TMP_DIR = ""; var template = new Loader("tpl1.mtt"); var page = template.execute({}); php.Lib.println(page); } }
main.hxml:
-php testTemplo -main Main -lib templo
tpl1.mtt:
::use tpl2.mtt::::end::tpl2.mtt:
<html> <head> <title>Test</title> </head> <body> Hello </body> </html>
Built everything like this:
temploc2 -output . -php tpl1.mtt temploc2 -output . -php tpl2.mtt haxe main.hxml
That generated a "testTemplo" output directory and the following two files:
tpl1.mtt.php:<?php $this->bufferCreate();$t_tpl1__mtt_0 = $ctx->tpl2->mtt;$this->includeTemplate($t_tpl1__mtt_0, 'tpl1__mtt', $ctx); ?>
tpl2.mtt.php:
<?php $this->buf .= '<html> <head> <title>Test</title> </head> <body> Hello </body> </html> '; ?>
Then I placed the *.mtt.php files in the testTemplo directory. Ran it through my web server/browser and got this:
uncaught exception: Trying to get property of non-object (errno: 8) in C:\Inetpub\wwwroot\testTemplo\tpl1.mtt.php at line #2Trying to get property of non-object in file: C:\Inetpub\wwwroot\testTemplo\tpl1.mtt.php line 2 #0 C:\Inetpub\wwwroot\testTemplo\tpl1.mtt.php(2): _hx_error_handler(8, 'Trying to get p...', 'C:\Inetpub\wwwr...', 2, Array) #1 C:\Inetpub\wwwroot\testTemplo\lib\templo\Loader.class.php(49): require('C:\Inetpub\wwwr...') #2 C:\Inetpub\wwwroot\testTemplo\lib\Main.class.php(10): templo_Loader->execute(Object(_hx_anonymous)) #3 C:\Inetpub\wwwroot\testTemplo\index.php(9): Main::main() #4 {main}
I'm using Haxe 2.05, templo 2.3.1, PHP 5.2.2, and WinXP Pro SP2 IIS.
-
Nick Sabalausky Feb 07 at 01:22
Ok, I got it working now. Here's the stuff I needed to change:
Main.hx:
// Change line #15 from: var page = template.execute({}); // To: var page = template.execute({tpl2:"tpl2.mtt"});
tpl1.mtt:
// Change line #1 from: ::use tpl2.mtt::::end:: // To: ::use tpl2::::end::
-
Philipp Klose Feb 07 at 17:31
The easiest way would be (as it is documented here: templo):
::use 'tpl2.mtt':: ::end:: -
Nick Sabalausky Feb 09 at 10:34
/smacks forehead/ I completely overlooked those quotes when I was looking at the docs. Oops :)
-
Nick Sabalausky Feb 09 at 10:35
(The single-quotes around the filename, I mean)