Code Monkey home page Code Monkey logo

templater's Introduction

Fast Templater

Быстрый легкий, шаблонизатор

Конструктор:

1 Аргумент: Дериктория шаблона (Необязательный)

2 Аргумент: расширение файлов шаблона (необязательный)

Метод compile:

1 Аргумент: ссылка на файл шаблона без дериктории шаблона и расширения файла если оно присвено ранее

2 Аргумент: Массив с данными где key будет заменен на value

3 Аргумент: Массив с Блоками [admin]Я админ[/admin] где key это идентификатор блока а value это определение показывать содержимое блока или нет (По умолчанию false)

4 Аргумент: ключ массива с данными шаблона (По умолчанию main)

5 Аргумент: не читать файл повторно если он был прочитан ранее

1 Пример

Содержимое файла index.php :

// Инклудим класс шаблонизатора
include __DIR__ .'/Templater.php';

// Обьявляем класс
$tpl = new Templater('/templates/', '.tpl');

// Компилируем и выводим в браузер
echo $tpl->compile("index", array(
  '{test-output}' => 'Test-output',
  '{test-output2}' => 'Test-output2',
  '{test-output3}' => 'Test-output3',
));

Содержимое файла /templates/index.tpl :

<DOCTYPE html>
<html>
 <head>
   <meta charset="utf-8">
 </head>
 <body>
   <p>{test-output}</p>
   <p>{test-output2}</p>
   <p>{test-output3}</p>
 </body>
</html>

Браузер

Test-output

Test-output2

Test-output3

2 Пример

Содержимое файла index.php :

// Обратите внимание что переменная равна true
$admin = true;

// Инклудим класс шаблонизатора
include __DIR__ .'/Templater.php';

// Обьявляем класс
$tpl = new Templater('/templates/', '.tpl');

// Компилируем и выводим в браузер
echo $tpl->compile("index", array(
  '{test-output}' => 'Test-output',
  '{test-output2}' => 'Test-output2',
  '{test-output3}' => 'Test-output3',
), array(
    'admin' => $admin //  [admin]Я админ[/admin]
));

Содержимое файла /templates/index.tpl :

<DOCTYPE html>
<html>
 <head>
   <meta charset="utf-8">
 </head>
 <body>
   [admin]<p>Я админ</p>[/admin]
   <p>{test-output}</p>
   <p>{test-output2}</p>
   <p>{test-output3}</p>
 </body>
</html>

Браузер

Я админ

Test-output

Test-output2

Test-output3

3 Пример

Содержимое файла index.php :

// Обратите внимание что переменная равна true
$admin = true;

// Инклудим класс шаблонизатора
include __DIR__ .'/Templater.php';

// Обьявляем класс
$tpl = new Templater('/templates/', '.tpl');

// Компилируем шаблон page
$tpl->compile("page", array(
  '{test}' => 'Скомпилирована',
), false, 'page');

// Компилируем и выводим в браузер
echo $tpl->compile("index", array(
  '{test-output}' => 'Test-output',
  '{test-output2}' => 'Test-output2',
  '{test-output3}' => 'Test-output3',
  '{page}' => $tpl->get['page'] // Ранее скомпилированный шаблон page
), array(
    'admin' => $admin //  [admin]Я админ[/admin]
));

Содержимое файла /templates/page.tpl :

Подстраница {test}

Содержимое файла /templates/index.tpl :

<DOCTYPE html>
<html>
 <head>
   <meta charset="utf-8">
 </head>
 <body>
   <p>{page}</p>
   [admin]<p>Я админ</p>[/admin]
   <p>{test-output}</p>
   <p>{test-output2}</p>
   <p>{test-output3}</p>
 </body>
</html>

Браузер

Подстраница Скомпилирована

Я админ

Test-output

Test-output2

Test-output3

templater's People

Contributors

alexandrukr avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.