[ERROR#1] How to add a template tag — Documentation — DIAFAN.CMS

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">
Methods with the same name as their class will not be constructors in a future version of PHP; Markdown_Parser has a deprecated constructor
#1 include_once() called at [/var/www/diafan/data/www/diafancms.com/modules/docs/docs.model.php:499]
#2 Docs_model->prepare_text( 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 ge...) called at [/var/www/diafan/data/www/diafancms.com/modules/docs/docs.model.php:94]
#3 Docs_model->show() called at [/var/www/diafan/data/www/diafancms.com/modules/docs/docs.php:29]
#4 Docs->init() called at [/var/www/diafan/data/www/diafancms.com/includes/init.php:474]
#5 Init->module() called at [/var/www/diafan/data/www/diafancms.com/includes/init.php:119]
#6 Init->start() called at [/var/www/diafan/data/www/diafancms.com/index.php:62]
/var/www/diafan/data/www/diafancms.com/modules/docs/docs.model.php:499