sinevia/php-library-template

v1.4.0 2019-02-17 20:29 UTC

This package is auto-updated.

Last update: 2024-04-16 18:43:52 UTC


README

Template is a simple, yet powerful templating engine in single file.

No Dependencies

Features

  • Single file. No external dependencies
  • No new "language" to learn. Familiar PHP syntax.
  • Default templates extension .phtml

Installation

Add the following to your composer file:

    "require": {
        "sinevia/php-library-template": "1.*"
    },

Functionality

1) From File

\Sinevia\Template::fromFile($templateFilepath, $data = array());

2) From String

\Sinevia\Template::fromString($templateString, $data = array());

3) Cache

\Sinevia\Template::setCacheDirectory($cacheDirPath);
\Sinevia\Template::setCache($key, $content, $options = array());
\Sinevia\Template::getCache($key, $options = array());

3) Helpers

\Sinevia\Template::minifyHtml($html);
\Sinevia\Template::minifyCss($css);
\Sinevia\Template::minifyJs($js);

Usage

$html = \Sinevia\Template::fromString($templateContent, [
     'page_meta_description' => $pageMetaDescription,
     'page_meta_keywords' => $pageMetaKeywords,
     'page_meta_robots' => $pageMetaRobots,
     'page_canonical_url' => $pageCanonicalUrl,
     'page_title' => $pageTitle,
     'page_content' => $pageContent,
]);
\Sinevia\Template::setCache('key','content',array(
     'post'=>true,
     'get'=>true,
     'session'=>true,
     'expires'=>3600 // Default
));

Layout

  1. Template file:
[layout::public/guest/layout.phtml]

CONTENT
  1. Layout file:
<?php echo $content; ?>