2017 © Pedro Peláez
 

library jte

Fast and flexible template engine

image

vitkovskii/jte

Fast and flexible template engine

  • Thursday, January 9, 2014
  • by vitkovskii
  • Repository
  • 0 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Jedi template engine

Fast and flexible template engine, (*1)

See example, (*2)

Use composer to install, (*3)

Main features

  • Separated markup and logic
  • Template inheritance
  • Super fast and simple
  • No dependencies

Basic usage

$jte = new Jte(__DIR__ . '/templates', ['useCache' => true, 'dir' => __DIR__ . '/cache/']);

echo $jte->render('template.jte', 'main', ['param1' => 'value1', 'param2' => 'value2']);

Template syntax

Template consists of sections. There are three section types:, (*4)

  • Boot section
  • Block markup section
  • Block logic section

Boot section

This section is executed then template is booting. Body of the section is pure PHP code., (*5)

If you want template extends another, you can specify it in this section:, (*6)

boot {
    extend('base.jte');
}

Dynamic inheritance:, (*7)

boot {
    extend(param('parent'));
}

More complex:, (*8)

boot {
    if (param('some') % 2 == 0) {
        extend('foo.jte');
    } else {
        extend('baz.jte');
    }
}

Block markup section

Block is an independent chunk of HTML or something else :), (*9)

markup some_block_name {
    <html>
        <head>
        </head>
        <body>
        </body>
    </html>
}

You can include references to another blocks into block:, (*10)

markup some_block_name {
    <html>
        <head>
        </head>
        <body>
            [[ body_block ]]
        </body>
    </html>
}

Also you can include tree of blocks:, (*11)

markup some_block_name {
    <html>
        <head>
        </head>
        <body>
            [[ body_block ]] {{
                <div>
                    [[ menu_block ]]
                </div>
                <div>
                    [[ footer_block ]]
                </div>
            }}
        </body>
    </html>
}

If you want to include passed param into template do this:, (*12)

markup footer {
    <div>
        User count: [[ user_count_block = user_count_param ]]
    </div>
}

Or anonymous variant:, (*13)

markup footer {
    <div>
        User count: [[ =user_count_param ]]
    </div>
}

Block logic section

With this block you can dynamically generate block contents from params or another blocks. Body of this block is pure PHP code., (*14)

Replace block with passed param:, (*15)

markup footer {


User count: [[ user_count_block ]]
} logic footer { replace('user_count_block')->with(param('user_count')); }

Replace block with another block:, (*16)

markup item {
    Foo :)
}

markup footer {


[[ footer_content ]]
} logic footer { replace('footer_content')->with(block('item')); }

Replace block with iterator:, (*17)

markup item {
    Foo :) [[ =count ]]
}

markup footer {


[[ footer_content ]]
} logic footer { replace('footer_content')->with(iterator([1, 2, 3], function($item, $count) { return block('item', ['count' => $count]); })); }

Self replacement:, (*18)

logic menu {
    replace('menu_items')->with(iterator(param('menu'), function($item, $count) {
        if ($count % 2 == 1) {
            $class = 'bg-1';
        } else {
            $class = 'bg-2';
        }

        $item['class'] = $class;

        return self($item);
    }));
}

markup menu {


}

To do

  • Add documentation for template inheritance mechanism
  • Add more examples

The Versions

09/01 2014

dev-master

9999999-dev

Fast and flexible template engine

  Sources   Download

MIT

The Development Requires

by Vitkovskii Vladimir

09/01 2014

0.1.0

0.1.0.0

  Sources   Download

MIT

The Development Requires

by Vitkovskii Vladimir