Answer the question
In order to leave comments, you need to log in
Description of variables used in the template
Should I describe the variables used in the template?
For example, there is such a template (view.php):
<h1>Hello, <?=$user?>!</h1>
$view = new View('view.php');
$view->assign('user', $user->name);
echo $view->render();
class SomePage extends View
{
/**
* Current user name.
* @var string
*/
public $user;
}
$view = SomePage();
$view->user = $user->name;
echo $view->render();
Answer the question
In order to leave comments, you need to log in
My opinion: if further development is planned and / or coding / layout will be performed by third-party people, it’s worth it. If you write only for yourself - as you prefer, but when specifying properties, it becomes possible to use autocommit in templates, which eliminates the need to constantly look at the code.
By the way, it is not necessary to create properties, you can use @property
:
/**
* @property string user
*/
class SomePage extends View {
}
I don't think there is a clear answer to this question. I would not do this: such a rule would multiply the amount of code many times over, but would not give a clear benefit.
I know that you didn't ask this and that it will be very difficult to switch to Smarty, but still, use Smarty, you will sin less. www.smarty.net/
I’ll tell you from my own experience - when you take your own code that you haven’t seen for several years, then sometimes with poor commentability it’s easier to rewrite :)
Of course, with the growth of professionalism, the code becomes more and more readable, but my humble opinion is that the description should always be. Moreover, it is often not always possible to understand what it means from the name of a variable. The defaults are different for everyone.
It is necessary to describe variables in the template engine, I even made an IDE for the template engine for such purposes in my bike . Convenient, visually shows variables and descriptions, in some places you can even move them. Everything is included from an external XML file, so it's easy to add new ones without getting into the IDE code. Of the minuses of the IDE - so far it only works in the windows.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question