2017 © Pedro Peláez
 

library blueprint

Simple template engine

image

sunkan/blueprint

Simple template engine

  • Monday, March 19, 2018
  • by sunkan
  • Repository
  • 0 Watchers
  • 0 Stars
  • 669 Installations
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 2 % Grown

The README.md

Blueprint

Installation

The preferred method of installing this library is with Composer by running the following from your project root:, (*1)

$ composer require sunkan/blueprint

Using

Simple example

Without external dependencies, (*2)

//index.php
$blueprint = new \Blueprint\Simple(new \Blueprint\Helper\ResolverList());
$blueprint->name = 'Blueprint';

//With the simple renderer youo have to add the complete path to template
echo $blueprint->render('tpls/index.php');

And the tpl file, (*3)

<!--tpls/index.php-->
<html>
<head>
<title>Index</title>
</head>
<body>
<h1>Welcome: <?=$name?></h1>
</body>
</html>

Example with template finder

//index.php
//if multiple directorys are specified they are search in lifo order
$finder = new \Blueprint\DefaultFinder();
$finder->addPath(__DIR__ . '/tpls/');

$template = new \Blueprint\Extended(
    $finder,
    new \Blueprint\Helper\ResolverList()
);
$template->name = "Sunkan";

//will include tpl from tpls/welcome.php
$response = $template->render('welcome');

//will include tpl from tpls/welcome.test.php
$response = $template->render('welcome', 'test');

echo $response;

And the tpl file, (*4)

<!--tpls/welcome.php-->
<html>
<head>
<title>Index</title>
</head>
<body>
<h1>Welcome: <?=$name?></h1>
</body>
</html>

Layout example 1

//index.php
//Same as previews example
//But you need to add a resolver to find the helper classes

$resolver = new \Blueprint\Helper\Resolver(function($cls) use ($finder) {
    return new $cls($finder);
});
$resolver->addNs('Blueprint\DesignHelper');

$blueprint->addResolver($resolver);

And the tpl file, (*5)

<!--tpls/index.php-->
<?php $view->design()->header()?>
<h1>Welcome: <?=$name?></h1>
<?php $view->design()->footer()?>
<!--tpls/layout/header.php-->
<html>
<head>
  <title>Layout type 1</title>
</head>
<body>
<!--tpls/layout/footer.php-->
</body>
</html>

Output:

<html>
<head>
  <title>Layout type 1</title>
</head>
<body>
<h1>Welcome: Blueprint test</h1>
</body>
</html>

Layout example 2

//index.php
//if multiple directorys are specified they are search in lifo order
$finder = new \Blueprint\DefaultFinder();
$finder->addPath(__DIR__ . '/tpls/');

$resolver = new \Blueprint\Helper\Resolver(function($cls) use ($finder) {
    return new $cls($finder);
});
$resolver->addNs('Blueprint\DesignHelper');
$resolverList = new \Blueprint\Helper\ResolverList([$resolver]);

$content = new \Blueprint\Extended($finder, $resolverList);
$content->setTemplate('index.php');
$content->name = "Sunkan";

$blueprint = new \Blueprint\Layout($finder, $resolverList);
$blueprint->setTemplate('layout/main');
$blueprint->setContent($content);

echo $blueprint->render();

And the tpl file, (*6)

<!--tpls/index.php-->
<?php $view->title('Set title from tpl');?>
<h1>Welcome: <?=$name?></h1>

<html>
<head>
  <title>Layout type 2 - =$view->title()?></title>
</head>
<body>

  =$content?>

</body>
</html>

Output:

<html>
<head>
  <title>Layout type 2 - Set title from tpl</title>
</head>
<body>
<h1>Welcome: Blueprint test</h1>
</body>
</html>

Configuration

TODO, (*7)

The Versions

19/03 2018

dev-develop

dev-develop https://github.com/sunkan/blueprint

Simple template engine

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by Andreas Sundqvist

19/03 2018

dev-master

9999999-dev https://github.com/sunkan/blueprint

Simple template engine

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by Andreas Sundqvist

19/03 2018

2.3.0

2.3.0.0 https://github.com/sunkan/blueprint

Simple template engine

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by Andreas Sundqvist

09/02 2018

2.2.1

2.2.1.0 https://github.com/sunkan/blueprint

Simple template engine

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by Andreas Sundqvist

09/02 2018

2.2.0

2.2.0.0 https://github.com/sunkan/blueprint

Simple template engine

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by Andreas Sundqvist

07/02 2018

2.1.1

2.1.1.0 https://github.com/sunkan/blueprint

Simple template engine

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by Andreas Sundqvist

07/02 2018

2.1.0

2.1.0.0 https://github.com/sunkan/blueprint

Simple template engine

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by Andreas Sundqvist

01/02 2018

2.0.0

2.0.0.0 https://github.com/sunkan/blueprint

Simple template engine

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by Andreas Sundqvist

09/06 2016

1.1.0

1.1.0.0 https://bitbucket.org/sunkan/blueprint

Simple template engine

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Andreas Sundqvist

26/10 2015

1.0.0

1.0.0.0 https://bitbucket.org/sunkan/blueprint

Simple template engine

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Andreas Sundqvist