How to add a template tag

Template tags allow executable code to connect to a specific location of the site.

DIAFAN.CMS makes no restrictions on the number of arguments and the function name.

The executable code may be a general nature or relate to the module.

If you want to add a general code, you create a common template tag.

To do this, add in the folder themes/functions need to add a file with the name tag.

After this template tag can be used.

Can transfer tag attributes. Attributes will be available through the array $attributes.

Example:

Add file hello.php.

<?php

if (! defined('DIAFAN'))
{
    
$path = __FILE__; $i = 0;
    while(!
file_exists($path.'/includes/404.php'))
    {
        if(
$i == 10) exit; $i++;
        
$path = dirname($path);
    }
    include
$path.'/includes/404.php';
}
echo
"Hello, ".$attributes["name"]."!";

Then in the site template, such as themes/site.php, the file can be executed anywhere template tag.

<insert name="hello" name="Andy">

Example:

Add in the module "News" template function show_date.

// in the file modules/news/news.php
public function show_date($attributes)
{
    
$attributes = $this->get_attributes($attributes, 'day', 'template');

    
$result = $this->model->date($attributes["day"]);
    echo
$this->diafan->_tpl->get('show_date', 'news', $result, $attributes["template"]);
}

// in the file modules/news/news.model.php
public function date($day)
{
    if(
$day)
    {
        
$result["date"] = $day.date(".m.Y");
    }
    else
    {
        
$result["date"] = date("d.m.Y");
    }
    return
$result;    
}

//file modules/news/views/news.view.show_date.php
echo '<div class="news_date">'.$result["date"].'</div>';

Then in the site template, such as themes/site.php, the function can be executed anywhere template tag.

<insert name="show_date" module="news">