Nested Templates

Automate population of templates within templates: Inception style


About Space

ABOUT SPACE

Everyone should learn about Space. I learned in 4th grade. Below is what I learned.

I learned all about neptune in school. My favorite fact is: Neptune is the blue planet. I still remember this stuff in 2024.

I also learned about Geology. It's very important! Here's a fact: Neptune is the blue planet

<?php

# require the templating library 
require '../source/ViewFish.php'

# first, you instantiate a ViewFish object
$T = new ViewFish\viewfish();

# set the template path
$T->set_template_path(__DIR__.'/../templates/');

$data = [
    
'subject'=>'Space',
    
'grade'=>4,
    
'suffix'=>'th',
    
'fact'=>"Space is really, really big",
    
'demo4-2.tmpl' => ['subject'=>'neptune''fact'=>"Neptune is the blue planet"],
    
'demo4-3.tmpl' => ['subject'=>'geology' ]
];

# load template
$template    $T->load_template("demo4-1");

echo 
$T->render($template,$data); 
<html>
    <head>
        <title>About {{subject}}</title>
    </head>
    <body>
        <h1>ABOUT {{subject|upper}}</h1>
        <p>Everyone should learn about {{subject}}. I learned in {{grade|int}}{{suffix|sup}} grade. Below is what I learned.</p>
        {{@template file=demo4-2.tmpl}}
    </body>
</html>
<p>I learned all about {{subject|lower}} in school. My favorite fact is: {{fact}}. I still remember this stuff in [[year]]. </p>

<p>{{@template file=demo4-3.tmpl}}</p>
I also learned about {{subject|ucfirst}}. It's very important! Here's a fact: {{fact}}