wol-soft / php-micro-template Goto Github PK
View Code? Open in Web Editor NEWA minimalistic templating engine for PHP
License: MIT License
A minimalistic templating engine for PHP
License: MIT License
Hello,
It would be nice to have some method to check syntax of the template.
I use your engine with Laravel/Nova application and I would like to have a validation function to check syntax before store it. into database.
I got stupid issues with foreach because I was trying to use PHP syntax instead of the correct one.
Thank you
Hello!
If I assign an object (e.g. a Laravel Eloquent model) as a variable and in the template I reference to a non-existent property of the object, the renderer throws an error instead of the UndefinedSymbolException, so I don't know, which property is missing.
TypeError(code: 0): array_key_exists(): Argument # 2 ($array) must be of type array, App\Models\Product given at /var/www/vendor/wol-soft/php-micro-template/src/Render.php:243
Thank You
thank you for this library, one thing i need to be able to customize the markers {% %} and the {{ }}
i was trying to replicate a template engine which uses $( and ) as start and end markers for variables, conditional and loop I dont want to edit the library but if its the case then theres no other choice
Does it possible to use function without embed them into a class ?
I mean for example:
class Formatters {
public static function dummy() {
return 'hello world';
}
}
...
$template = "{{dummy()}}F{{date.format('Ymd')}}-{{sequence.format(8)}}";
$result = $render->renderTemplateString(
$template,
[
'date' => new DateFormatter,
'sequence' => new SequenceFormatter,
'dummy' => Formatters::dummy,
]
...
Hello,
Does it possible to use dotted notation to access variables? It looks that doesn't works for me...
$data = [
'ticket' => [
'id' => 14,
'title' => test
]
];
$pattern = ' wo-{{ticket.id}}';
echo $render->renderTemplateString($pattern, $data);
Thank you
You should add use PHPMicroTemplate\Render
to your example cuz people don't know the name of namespace where Render
is located (they going to look into src/Render.php
file to determine this).
Hello,
How can I catch missing or unknown variables without stop rendering?
Maybe it would be possible to add some callback to replace unknown variables by any string ...
Thank you
Hello,
I'm using functions with your template renderer, but I've got an issue with parameters.
I'm unable to pass string or number as parameter directly
$template = "F{{format.date('Y')}}-{{format.sequence(8)}}";
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use PHPMicroTemplate\Render;
use Carbon\Carbon;
class TemplateFormat {
public function sequence($digits=6) {
return sprintf('%0'.$digits.'d', 7);
}
public function date($format='Y') {
return Carbon::now()->format($format);
}
}
class Template extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'template:render';
/**
* The console command description.
*
* @var string
*/
protected $description = 'replace variable into template';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$render = new Render();
$template = "F{{format.date('Y')}}-{{format.sequence(8)}}";
$result = $render->renderTemplateString(
$template,
[
'format' => new TemplateFormat,
]
);
echo $result . PHP_EOL;
return Command::SUCCESS;
}
}
Any idea what I'm doing wrong?
Regards
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.