GithubHelp home page GithubHelp logo

jaypha / j-plate Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 9 KB

Hierarchical components incorporating a PHP based template engine (deprecated, use Jayponents)

License: Boost Software License 1.0

PHP 99.51% Smarty 0.49%

j-plate's Introduction

Jaypha Templates

Written by Jason den Dulk

A simple, yet powerful template engine.

Features

  • Uses PHP itself as the template engine, so no need to reinvent the wheel or use bloated parsers and interpreters, or learn yet another language.

  • You can create custom component classes that allow you to have extra component specific business logic that can be kept out of the template, or handle boilerplate you dont want to have repeated in every template file.

  • Specify the template either as a string or a file.

  • Direct output. Displays content directly to output for faster rendering. Output to a string (via __toString) is also supported.

  • Hierarchical. Components can be added to other Components to create output of arbitrary complexity. No need for partials, layouts or helpers as Component can be used for all of these roles.

Requirements

PHP v5.4.0 or greater.

Installation

composer require jaypha/j-plate

API

class Component

__construct($template, $initialData)

Constructor for the Component class.
$template - The template file to use.
$initialData - Associative array for values to be used. May be non-associative if no template is provided.

void setTemplate(string $template = null) Sets the template file

void setVars(array $values) Sets all the values.

void set(string $name, mixed $value) Sets a single value

void remove(string $name) Removes a value stored under $name.

void add(mixed $value) Adds a value without a name. Useful when no template is being used.

void clear() Removes all values.

void display() Outputs the contents to the output context.

string __toString() Returns the contents as a string.

trait TextComponentTrait

A trait that allows the template to be provided directly instead of via a file.

class TextComponent

Behaves the same as Component except that the template is provided directly instead of via a file.

How to use templates

This project make use of PHP's ability to embed PHP code inside a text file. Simply surround your code with <?php and ?>, or <?= and ?>.

All values are loaded into the context and can be accessed directly. For example, a value set with the name viewName, can be printed with <?=$viewName?>.

License

Copyright (C) 2017 Jaypha.
Distributed under the Boost Software License, Version 1.0.
See http://www.boost.org/LICENSE_1_0.txt

j-plate's People

Watchers

James Cloos 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.