2017 © Pedro Peláez
 

library pytotpl

A PHP template engine

image

pytocryto/pytotpl

A PHP template engine

  • Thursday, April 26, 2018
  • by PytoCryto
  • Repository
  • 0 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

PytoTPL template engine

Installation

Install via composer, (*1)

composer require pytocryto/pytotpl

Initiate & configure PytoTPL, (*2)

$tpl = new \PytoTPL\PytoTPL();
$tpl->setConfig([
    'tpl_folder'      => __DIR__ . '/dir/to/templates/',
    'cache_folder'    => __DIR__ . '/dir/to/cache/',
    'tpl_file_format' => '.tpl',
    'compress'        => false, // compression only available in a valid <HTML> document
    'event_emitter'   => true, // set to false for better performance
]);

Outputs:

{$variable}

{$array.key1.key2.key3}

{echo $variable}

{print $variable}

{$variable|substr:0,-1}

Unescaped output:

{!! $variable !!}

Loops:

{foreach: $myArray as $item}
..
{/foreach}

{for: $i = 0; $i < 99; $i++}
..
{/for}

{while: $i < 9}
..
{/while}

If Statements:

{if: date('Y') == 2017}
    Yey, its 2017!
{elseif: date('Y') == 2018}
    Yey, its 2018!
{else}
    NOOOOo :(
{/if}

PytoTPL provides a few shortcuts, instead of having to write conditions like:, (*3)

{if: isset($data)}
    Yes
{else}
    Nope
{/if}

{-- or --}

{if: empty($data)}
    ...
{/if}

you'd instead write:, (*4)

{isset: $data}
    Yes
{else}
    Nope
{/isset}

{-- or --}

{empty: $data}
    ...
{/empty}

Conditions

{continue}
{break}
````
Instead of writing the long-way condition, e.g:
```html
{if: $userid == 1}
    {continue}
{/if}

You can simply include the condition in one line:, (*5)

{continue: $userid == 1}
{break: $userid == 1}

Extending/including an layout:

{extend 'header'}

Set a variable:

Note: When setting a variable with PytoTPL-syntax you don't have to end it with a semicolon ";", (*6)

{var $myVariable = 'My value here'}

{-- or --}

{assign $myVariable = 'My value here'}

Using ternary operators:

{$_GET['id'] OR 'No id has been set!'}

Comments:

{-- Anything here is just a PHP comment --}

Sections (NOT TESTED YET!):

Note: Section names must be written as word characters., (*7)

{section: mySection}
...
{/section}

If you want to pass variables to the section you may do so:, (*8)

{section: mySection, varName=Value}
...
{/section}

You can also overwrite a section using the following syntax, (*9)

{section.overwrite: mySection}
...
{/section}
To render a section
{section.view: mySection}

The Versions

26/04 2018

dev-master

9999999-dev

A PHP template engine

  Sources   Download

MIT

The Requires

 

The Development Requires

26/04 2018

1.0.0

1.0.0.0

A PHP template engine

  Sources   Download

MIT

The Requires

 

The Development Requires

26/04 2018

dev-develop

dev-develop

A PHP template engine

  Sources   Download

MIT

The Requires

 

The Development Requires