Closed resurtm closed 11 years ago
Idea is definitely good.
<?php
will be actually rendered.$b = $this->preprocess($a);
$b = empty($b) ? 'default' : $b;
echo Html::encode($b);
I like standardization as it generally helps understanding unknown code. Also, I like your proposed style. But there are two things that should be kept in mind:
This issue is about proposing view code style and discussing it.
Proof of necessity
I think view code conventions must be also documented and described for an end users, developers and core developers, just like it is made for the common Yii2 PHP code. Understanding of the problem may come after some real world samples.
Consider developer M wrote the following view code:
Then his colleague N started to discuss and change view code on his own. After his changes view may become to something as follows:
His main argument on this change: why do we need so much PHP tags? Isn't better to remove them all and code would be much more readable? Abscence of common prescribed view style causes waste of time and pointless debates.
Moreover third developer P could rewrite views above in absolutely different manner:
This third variant looks even worse and ugly (from objective POV). I am sure his colleagues M and N shall hate this fashion of template decoration. :-)
In Yii 1.1 everyone is writing views/templates on their own, without any common conventions. Imagine big team of developers where many people can edit single view file. I realize big teams usually have their own internal conventions, but why not to create them at the framework level?
Moreover i think it would be very comfortable for every developer when 100% of created applications would have absolutely identical view decoration style. In this case there won't be need to get used to the style of an existing project, in case you have to move from one project to another.
Proposed view code style
Without comments (raw):
With comments:
What do you think about idea itself and proposed view style? For this case i think we can create additional Wiki page.