Documentation

Template
in package

This basic template system gets you off to a start.

Tags
link
https://git.lattuga.net/netico/code-library/src/master/Framework
copyright

Copyright (c) 2016, 2022 netico netico@riseup.net

license

https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License

author

netico netico@riseup.net

Table of Contents

__construct()  : void
It requires the path to the template file.
add()  : void
The method adds a variable to the template.
output()  : void
This method prints the HTML code.
rs()  : void
This method also provides support for repeating sections.
section()  : void
This method provides support for repeating sections.

Methods

__construct()

It requires the path to the template file.

public __construct(string $template) : void

You can refer to the TEMPLATES constant.

Parameters
$template : string

File path to template file.

Return values
void

add()

The method adds a variable to the template.

public add(string $key, string $value) : void

This example describes how variables can be used within templates.

PHP code:

 $t = new template("template.tpl");
 $t->add("foo", "Barletta");
 $t->output();

HTML code:

 I love {foo}

Output:

 I love Barletta
Parameters
$key : string
$value : string
Return values
void

output()

This method prints the HTML code.

public output(string $mime) : void

Read https://stackoverflow.com/questions/6225351/how-to-minify-php-page-html-output, that explains how to minify HTML code.

Parameters
$mime : string
Return values
void

rs()

This method also provides support for repeating sections.

public rs(array<string|int, mixed> $res, string $section) : void

The first parameter is an array constructed from the results of an SQL query. The second parameter indicates the section with the name used in the template.

PHP code:

 $db = new \netico\Bones\SQLite();
 $db->sql("SELECT [id], [title], [text] FROM pages ORDER BY [id] ASC;");
 $s->rs($db->data, "pages");

HTML code:

 <!-- open(pages) -->
 <h2><a name="{id}">{id}. {title}</a></h2>
 <div>{text}</div>
 <!-- close(pages) -->
Parameters
$res : array<string|int, mixed>
$section : string
Return values
void

section()

This method provides support for repeating sections.

public section(string $key) : void

PHP code:

 $t->section("planets");
 $t->add("planets.name", "Neptune");
 $t->add("planets.group", "Gas giant");
 $t->section("planets");
 $t->add("planets.name", "Saturn");
 $t->add("planets.group", "Gas giant");

HTML code

 <!-- open(planets) -->;
 <p>Name: {name} - Group: {group}</p>
 <!-- close(planets) -->;

Output:

 Name: Neptune - Group: Gas giant
 Name: Saturn - Group: Gas giant
Parameters
$key : string
Return values
void

Search results