Download the PHP package louis-dj/xml-template without Composer
On this page you can find all versions of the php package louis-dj/xml-template. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download louis-dj/xml-template
More information about louis-dj/xml-template
Files in louis-dj/xml-template
Package xml-template
Short Description Xml templating engine for dynamic xml string generation in php
License MIT
Informations about the package xml-template
Xml Templating for php
Generate dynamic xml strings using templated xml files.
Motivation
Avoid building dynamic xml strings with messy string concatenations in your code.
Avoid adding static boilerplate elements when using a useful package like ArrayToXml.
Usage
Install the package with composer:
Create an xml file with templating directives
Import the package and convert with the replaceWith method
Absolute filepaths AND relative filepaths(relative to cwd) are supported
Features
- Minified: The
replaceWithmethod has an optional boolean parameterminifiedto remove all newline characters from the xml - Object & Array compatibility: The associative array passed to the
replaceWithmethod can contain string keys OR objects with field names corresponding to the variables OR both - See the syntax below for full feature set
Syntax & Rules
- All directives must be enclosed in
{{}}and contain a space on the inside of both pairs - Variable names use a global scope, even variables defined in
foreachdirectives - All directives can be freely nested as long as it is property closed with an
enddirective if,else,foreachandenddirectives must be on their own line, but may be indented.
Variable Directives
If statements
- All
ifstatements must be closed by anenddirective
If else statements
- All
if elsestatements must be closed by anenddirective
Foreach statements
- All
foreachstatements must be closed by anenddirective
Foreach as statements
- All
foreach asstatements must be closed by anenddirective
Attribute access
- The dot (.) operator works to access associative array keys' values too.
Pass in Objects to the replaceWith method
- View
tests/Test.phpfor more detailed use cases
Testing
Testing is done with phpunit and all tests are contained in the tests/ directory.
Run tests with: