Download the PHP package oscarpalmer/yogurt without Composer
On this page you can find all versions of the php package oscarpalmer/yogurt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download oscarpalmer/yogurt
More information about oscarpalmer/yogurt
Files in oscarpalmer/yogurt
Package yogurt
Short Description A tiny templating engine.
License MIT
Homepage http://git.io/yogurt
Informations about the package yogurt
Yogurt
Yogurt is a template language for PHP (>=5.3
) inspired by Beach's Hammer. Hammer's syntax was based on regular ol' HTML comment tags, so you won't have to install another syntax highlighter for your editor. Nice, huh?
Getting started
Installation
Yogurt is available via Composer.
Basic usage
Syntax
The syntax is based on regular HTML comments and the control structures (if
and foreach
) are based on Twig's syntax, so it shouldn't be too difficult to learn.
Variables
variable
is a direct child of the data object ($flavour->data();
), and the chaining.variables.works.too
is a nested child of multiple arrays or objects inside the data object.
Variables should be of the scalar
type, i.e. boolean
, float
, integer
, or string
. If not, PHP will scream.
Variable modifiers
Variables can be modified, too.
dump
: dumps the variable withvar_dump
.escape
: escapes bad characters, e.g. tags.json
: transforms anything into valid JSON markup.lowercase
: converts the string to a lowercase version of it.trim
: trims the string of leading and trailing whitespace.uppercase
: converts the string to an uppercase version of it.
Including other files
Yogurt will then attempt to find the file in the directory supplied to Yogurt as shown in the "Getting started" example; the second one will automatically append the supplied file extension.
Looping
items
should be an array or object, but item
can be whatever; just remember to chain names to access the item's children if it isn't scalar
, like this: item.title
.
Indexes
When looping, sometimes you need to know the index of the item – i.e. its place in the array or object. The item's index can be accessed by appending _index
to the array or object's name, e.g. array_index
for an array named array
.
Ifs and else-ifs
Supported comparison operators are ===
, ==
, !==
, !=
, >=
, <=
, <>
, >
, <
, is
, and isnt
. is
and isnt
will be turned into ==
and !=
respectively.
Values can be scalar
, null
, or variables. boolean
, float
, integer
, and null
values can be wrapped in quotation marks, but don't necessarily need them.
Strings however, do need quotation marks; if they're not wrapped in quotation marks, they're assumed to be variables.
Todo
- More string modifiers.
- Adding and removing custom modifier functions.
- Adding and removing custom parsers functions?
- Caching?
License
MIT Licensed; see the LICENSE file for more info.