What you think about a simple template engine that uses standard php syntax.

47 views
Skip to first unread message

HwapX

unread,
May 11, 2018, 12:09:24 PM5/11/18
to f3-fra...@googlegroups.com
I was thinking about an template engine that use "standard" php syntax but that escapes content and allow magic template functions like fatfree

The syntax basically will be.

Code Block(short open tags can be fixed when parsing).
<?


?>

Escape code block opening tag
@<?

Template Function
<? @func('test'); ?>

Suppress error
<? @@func('test'); ?>

Echo
<?= 'text' ?>


What i want with this is:
  • Safety.
  • Standard php syntax highlight works.
  • Standard php autocomplete works.
  • In my tests php linting works.
  • When an error occurs, the line will match that of the template.
  • With template functions you can avoid (but still can) writing boilerplate like "$this->func" and "\Namespace\Class::xxx".
  • Because of the use of standard php syntax it dont break editor autocomplete when when you dont close all tags between control blocks like happens with the syntax of fatfree template class.
  • fat free.
I'am not wanting to replace or add this to fatfree, just want to know what you think.

ikkez

unread,
May 12, 2018, 4:28:55 AM5/12/18
to Fat-Free Framework
isn't the View engine exactly doing this?
https://fatfreeframework.com/3.6/view

HwapX

unread,
May 12, 2018, 12:07:13 PM5/12/18
to Fat-Free Framework
To be honest I forgot the View class, when this idea came up I was only with the Preview and Template classes in mind, but the View class solves almost everything.

Except for the "boilerplate" code, but this can be solved by creating something like default variables that will always exist in every template context, such as.
$view->setDefaultVars(array(
   
'view' => $view,
   
'base' => \Base::instance(),
   
'helper' => \MyHelper::instance()
));

or maybe some ini settings, anyway those ideas probably are not interesting to the fatfree itself, in my project I'm going to create a class inheriting from View to add this.

You prevented me from reinventing the wheel, thanks.
Reply all
Reply to author
Forward
0 new messages