Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include template in template Mustache.php

Tags:

php

mustache

I have 3 template files:

main.tpl
main_header.tpl
main_footer.tpl

I need to include the last 2 templates inside the first one using Mustache.php
I can't find documentation about it.

How can I do?

like image 484
Fez Vrasta Avatar asked May 10 '26 04:05

Fez Vrasta


1 Answers

The included templates are called "partials" in Mustache. The tag to include them looks like this:

{{> main_header }}
{{> main_footer }}

You will need to set up a template loader so that Mustache can automatically load them.

Since your file extension is .tpl, you should also let your template loader know.

The resulting code probably looks something like this:

<?php

$m = new Mustache_Engine(array(
    'loader' => new Mustache_Loader_FilesystemLoader(
        __DIR__.'/path/to/views',
        array('extension' => '.tpl')
    ),
));

echo $m->render('main', $data);
like image 169
bobthecow Avatar answered May 11 '26 19:05

bobthecow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!