Skip to the content.

Multi Platform Template System

This is html and xml template system. It is created to be used in multiple programming languages.

It’s like Twig, but better.

Table of content

Table of contents generated with markdown-toc

Demo

https://greencodestudio.github.io/mpts/demo/

Examples

Real working examples available on github

Usage in code

PHP

composer require mkrawczyk/mpts
use MKrawczyk\Mpts\Environment;
use MKrawczyk\Mpts\Parser\XMLParser;

$template = XMLParser::Parse(file_get_contents(__DIR__ . '/file.mpts'));
$env = new Environment();
$env->variables = ['foo' => 'bar'];
echo $template->executeToString($env);

JS

let parsed = XMLParser.Parse(code);
let env = new Environment();
env.variables = {foo: 'bar'}
document.body.append(parsed.execute(env));

JS with webpack

webpack.config.js:

module.exports = {
    module: {
        rules: [
            {
                test: /\.mpts$/,
                loader: "mpts-loader",
            },
        ],
    },
};

and in code

import template from "./template.mpts"

document.body.append(template({foo: 'bar'}))

JS with VUE

webpack.config.js:

module.exports = {
    module: {
        rules: [
            {
                test: /\.mpts$/,
                loader: "mpts-vue-loader",
            },
        ],
    },
};

and in code

<template>
    <div>
        <subcomponent/>
    </div>
</template>
<script>
    import subcomponent from "./subcomponent.mpts"
    export default {
        components:{subcomponent},
    }
</script>
document.body.append(template({foo: 'bar'}))

Language supported

PHP

mkrawczyk/mpts Readme.md

JS

Main package mpts-core

Webpack loader: mpts-loader

Webpack loader for Vue: mpts-vue-loader

.NET

MPTS

Manual

Text

MPTS allows You to use expressions that returns text.

<h1></h1>
<p></p>

Expressions can also be more complicated


Everythink written using is XSS safe, ho html injection is possible.

Elements

All attribute’s values are threated as expressions, but text in quotes “ “ or ‘ ‘ is threated as static string

<div class="2+2" title=2+2/>

will produce

<div class="2+2" title="4"></div>

Expressions

Expressions is everythink you can write:

Becouse MPTS is language-agnostic, all available expressions are identical for all platforms and languages.

Variable

You can use variables provided from external source or scoped variable (by <:variable/> <:foreach/> or <:loop/>)

Property

You can extract property of variable using .. The same symbol is used for all programming languagfes you use MPTS with.

Using with PHP you can use . both for arrays and objects.

Method call

With variables You can provide functions (in C# delegates, in PHP callables), or objects, that have methods.

Methods/functions can get parameters.

function1()
obj.method(param1, param2)

You can use what method returned as parameter to other method, also method can return other method.

function1(function2(), function2().property)()