Download the PHP package leongrdic/dataplater without Composer

On this page you can find all versions of the php package leongrdic/dataplater. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package dataplater

Dataplater

release php-version license run-tests

try

Dataplater is a templating engine written in PHP that uses HTML data-attributes and keeps templates valid and clean. This makes Dataplater perfect for creating document templates like invoices, contracts, emails, etc. which can be previewed in the browser before rendering.

Features

Examples

I actually created an invoice template for Dataplater that's used in production. The template's source code is here.

Install

Requirements

Usage

When creating a Dataplater object, you can either provide a path to your template file or pass the template as a string. The recommended way to initialize the object is by using PHP8's named arguments.

Optional parameters:

render() method

The render() method renders the template and returns the rendered HTML as a string.

The optional parameter is an array of local vars that will override any global vars with the same name.

You can call this method multiple times on the same object with different vars to render multiple variants of the same document.

Attribute reference

If you change the base attribute to e.g. data-custom (when creating the Dataplater object), use data-custom-foreach instead of data-dp-foreach.

All Dataplater attributes will be automatically removed from the template after rendering.

data-dp-include

Value: filename of the HTML template to include.

Content of the included file will be inserted into the document replacing the element with the data-dp-include attribute.

data-dp-if

Value: SMPL expression

If the expression evaluates to true, the element will be rendered, otherwise it will be removed.

try

data-dp-foreach

Value: SMPL expression

Additional attributes:

The expression must evaluate to an array or an iterable object. Children of the element with the data-dp-foreach attribute will be copied for each iteration and the data-dp-key and data-dp-value vars will be set to the current element key and value to be used in those child elements.

The element containing the data-dp-foreach attribute will be removed after the loop.

try

data-dp-html

Value: SMPL expression

If the expression evaluates to null, no action will be taken (the element will be rendered without any modifications).

The expression otherwise must evaluate to a string. The string will be inserted into the element as HTML replacing the element's content.

The inserted HTML will have only data-dp, data-dp-attr and attribute shortcuts rendered which means that other attributes like data-dp-if or data-dp-foreach will be ignored.

Note the quotes around the expression in the second example - the outer quotes are defining content of the HTML attribute and the inner quotes are defining a string within the SMPL expression.

try

data-dp

Value: SMPL expression

If the expression evaluates to null, no action will be taken (the element will be rendered without any modifications).

The expression otherwise must evaluate to a string. The string will be inserted into the element as escaped text replacing the element's content.

Note: HTML interprets the attribute from the last example as: data-dp="`cool`", and SMPLang will interpret `cool` as a string literal. If you wrote data-dp="cool" instead, SMPLang would look for a var called cool and return its value.

try

data-dp-attr

Value: attribute name ; SMPL expression

If the expression evaluates to null, the attribute won't be set, and it's value will be left as is (if any).

The expression otherwise must evaluate to a string. The string will be escaped and inserted as the attribute value for the desired attribute.

Dataplater also provides a few shortcut for the following attributes: id class title alt value href src style using the syntax: data-dp-attribute.

try

Expression reference

Dataplater uses the SMPLang expression language. Refer to the SMPLang readme for more information about the syntax and supported operators.

Vars from Dataplater are accessible as vars in the SMPL expression.

Dataplater also provides a global object php which is basically a proxy to all php functions. Use it to access any PHP function from within your expressions:

Keep in mind you can still pass your own closure/function vars and use them in your templates.

When the expression returns a closure, Dataplater will attempt to call it (without any params) and use the result instead of the closure.

Dataplater wraps all SMPL exceptions in a \Le\Dataplater\ParseException which gives you access to the line number and the causing HTML element.

Rendering order

  1. Includes are inserted (single level only)
  2. if checks are performed (except for those in loops)
  3. Loops are performed (recursively) and their contents are fully rendered (which allows for nested loops; including if checks)
  4. HTML insertions are performed
  5. Text and attribute insertions are performed

Notes

Dataplater heavily relies on the PHP DOM extension and all escaping is done by the DOM extension natively, so passing user-generated data into Dataplater vars should be safe, although if you do use data from untrusted sources, make sure proper validations is done.

Also keep in mind that DOM extension sometimes reformats HTML (like adds attribute brackets, removes closing tags if unnecessary, etc.) and that the code coming out of Dataplater is not going to be indented well.

Any contributions to this project are welcome!


All versions of dataplater with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
ext-dom Version *
ext-libxml Version *
leongrdic/smplang Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package leongrdic/dataplater contains the following files

Loading the files please wait ....