2017 © Pedro Peláez
 

library xtpl

PHP/Ajax Template Render Class

image

jakiboy/xtpl

PHP/Ajax Template Render Class

  • Saturday, May 19, 2018
  • by Jakiboy
  • Repository
  • 1 Watchers
  • 1 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Xtpl (Ajax Template Transformer)

Xtpl is a tiny powerful HTML/Ajax rendering class for PHP >= 5.6 using shortcode system, Similar to Symfony renderView, but comes with new features. Xtpl is a Bundle of FloatPHP Framework, works in FloatPHP projects, and also available for non-framework projects, and as a Symfony Bundle too., (*1)

Maintainability, (*2)

Which projects ?

Like Load more system, when fetching data from SQL request to HTML target, using jQuery append function. For example, in place of (Hardcoding) building result HTML With PHP in Controller and return content, you can simply define shortcodes in target (HTML Template), then use Xtpl class to retrun rendered result content., (*3)

For what ?

In this case, editing template w'll be simple because HTML template is separated from logical, and controller is quickly maintainable. And in big term, Xtpl is dedicated for keeping clear MVC Pattern., (*4)

How it works ?

The basic concept is on shortcodes and keys of result SQL arrays, the class transform shortcodes names to value of data with the same names of array keys, for example; in template the shortcode <span>{name}</span> is placed, and in SQL result Multi-dimensional Array ['name'=>'John'] etc, then rendered result should be <span>John</span>., (*5)

How to use ?

Basic usage :, (*6)

include('Xtpl.php'); // our class
$multiple; // Multi-dimensional Array of SQL result, (SELECT * FROM example)
$x = new Xtpl('template.tpl'); // instance with template path
echo $x->transformAll($multiple)->response; // return result for Ajax call

What methods ?

transformAll :, (*7)

Transform all shortcodes with entities (attributes), shortcodes replacements are defined automatically, shortcode Must be compatible with returned data, eg. if in data array an attribute is named phone, shortcode in template Must be {phone}, or you can customize shortcode with setDelimiter method. transformAll method works onlly on multi-dimensional array, as an SQL response., (*8)

echo $x->transformAll($multiple)->response;

transform :, (*9)

transform method works on non multi-dimensional array as a single shifted array, (*10)

echo $x->transform($single)->response;

setDelimiter :, (*11)

Customize shortcodes, or even use multiple shortcodes : [shortcode], (*12)

$x->setDelimiter('[',']');

shortcodeIn :, (*13)

Return boolean of shortcode existence on template, Must use setDelimiter method to detect other shortcodes with different delimiters, (*14)

$x->shortcodeIn('{name}'); // return false|true

clear :, (*15)

Clear non-replaced shortcodes, Must be used before response, (*16)

echo $x->transformAll($multiple)->clear()->response;

Other Use case ?

Usage for static method :, (*17)

echo Xtpl::build('template.tpl')->transformAll($multiple)->response;

Transform all with extra shortcode :, (*18)

    $x->transformAll($multiple);
    $x->transform(['date'=>'22/10/2017']); // {date}
    echo $x->response;

transform method on multi-dimensional array using loop :, (*19)

    foreach($multiple as $single) {
     $x->transform($single);
    }
    echo $x->response;

Separated transform method on non multi-dimensional array :, (*20)

    echo $x->transform(['id'  => '1'])
           ->transform(['name' => 'john'])
           ->transform(['mail' => 'john@mail.com'])
           ->transform(['phone'=> '012345678'])
           ->response;

Both transform and transformAll on multi-dimensional array :, (*21)

echo $x->transformAll($multiple)->transform($single)->response;

The Versions

19/05 2018

dev-master

9999999-dev

PHP/Ajax Template Render Class

  Sources   Download

MIT

19/05 2018

1.0

1.0.0.0

PHP/Ajax Template Render Class

  Sources   Download

MIT

07/10 2017

0.1.0

0.1.0.0

ajax teemplate

  Sources   Download

MIT