Pro's and cons of template engine?

I think it just adds complexity! in my opinion cleanness directly relates to readability, and this riddle like syntax is everything but readable :)

Using this, one has to look for a manual on how to write simple html tags! having shorter lines does not make a view cleaner. I prefer real HTML tags.

It is not complicated at all :)

A tag is prepended by a percent sign, %h, %div, %span, …

A class is .class-name and an id is #id-name.

When dealing with divs, they are the default type, so instead of typing %div.site-login, you simply type .site-login.

For larger templates, it really makes it cleaner. :)

6789

html.png

6788

haml.png

If it makes me happy … :)

That is MtHaml in Twig mode, by the way.

What I showed you earlier is MtHaml in PHP mode, which is probably more Yii-kosher.

I agree that it’s some cool and fun to use stuff. but I doubt using it in a large real world project with numerous team members with different skill levels :) keeping things simple worth those more characters!

Hmm, I personally agree with Hesam K, although I think I could understand the elegance of some template language that jacmoe is fascinated by.

Shorter source code doesn’t always mean simpler and easier code, IMO.

I’m a programmer who prefers to write




$a = someFunc();

if ($a !== false) {

    ...

}



than




if ($a = someFunc()) {

    ...

}



And, to use a template language, you have to learn something additional other than HTML and PHP. It surely is an extra burden for me.

Jade and Haml are already used by large teams in huge projects. :)

Besides, the tags are the same, and if you use the php version of MtHaml, then the code is the same.

The only real difference is much less typing.

I don’t use the templating abilities of Haml/Jade when using them with Yii - it’s only to be able to write less.

And if I can write less, I make less amount of errors.

I will probably resurrect this topic once I have coded up my Yii2-JadeRenderer extension.

I think that people are using Coffeescript for many of the same reasons… :)

I have written a first edition of Yii2-tale-jade which is a Jade renderer for Yii2 using the Tale Jade for PHP library.

The syntax is slightly cleaner than MtHaml, and you can actually debug the templates easily, even though you are not shown the source but the compiled php file.

However, the extension is still in the early stages.

Still, it is already fully usable. :)

Here is the main layout in Jade:

https://gist.github…3c44907dbaa4605

An a small excerpt:


-use yii\helpers\Html

-use yii\bootstrap\Nav

-use yii\bootstrap\NavBar

-use frontend\assets\AppAsset

-use frontend\widgets\Alert

-use yii\widgets\Breadcrumbs

-AppAsset::register($view)

-$view->beginPage()


doctype html

html(lang=Yii::$app->language)

  head

	meta(charset=Yii::$app->charset)

	meta(name="viewport", content="width=device-width, initial-scale=1")

	!=Html::csrfMetaTags()

	title #{$view->title} | Bugitor

	-$view->head()

  body

	-$view->beginBody()

	.wrap



For me, it makes the most sense to pick a templating language that is widely used.

Jade is the default for the Node.js community (which is huge).

;)

Edit:

Project link: https://bitbucket.org/jacmoe/yii2-tale-jade

I agree with you on that.

Keep it simple and don’t try to be too clever.

However, I really believe that a cleaner syntax leads to cleaner code and thus less room for error.

First: the syntax for Tale Jade is Jade and PHP.

PHP you already know.

And Jade is simply short-hand HTML and you know that you know that.

I am so lazy that I am willing to spend weeks of hard work so that I don’t have to do all that tedious typing! :lol:

If you take a look at yii2-tale-jade and the syntax you will see that it really just is html tags and good old PHP.

There are no ugly php start and end tags and no brackets, not even curly ones (except in the PHP code, obviously).

If you are really lazy, you can just include a plain PHP file in the Tale-Jade templates and call it the day. :)

Edit: My primary reason for using a template language with Yii/PHP right now is not so much for the templating features, but for cleanliness / reduced typing.

I might go nuts later with Jade blocks and mixins - I probably will! but for now the main motivation is to be able to work Emmet-like.