Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 views
in Technique[技术] by (71.8m points)

php - Lightweight PHP5 based template class/system

Looking at using a template system for a new project, it's only a small site and don't want to use the overhead and 'complexity' of smarty. I don't really like template systems that force you to make use of another language just to make it easier for designers (apparently).

Something like this http://www.namepros.com/code/517342-php5-template-class.html is what Im looking at but something which is a bit more robust and proven.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

TWIG

I would recommend using Twig

  • extensible syntax
  • efficient
  • compiles and caches your templates to PHP classes with a very small overhead
  • sandbox mode to evaluate untrusted template code
  • unit tested
  • great documentation
  • multiple template inheritance, template blocks, automatic output-escaping

Also read Fabien Potencier's blog post, where he explains needs for a powerful and customizable template engine.

TWIG Template code

{% extends "layout.html" %}

{% block title %}
    {{ page.title|escape|title }}
{% endblock %}

{% block content %}
    Content of the page...

    {% for user in users %}
      * {{ user.name }}
    {% else %}
        No user has been found.
    {% endfor %}

{% endblock %}

{# this is a comment in twig syntax #}

Symfony Components

Also if you need additional components for web development, but you already have a defined code base, have look at Symfony Components which includes additional templating component (mentioned in XUE Can answer)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...