Googling, reading a bunch of articles, I came to the conclusion that the use of templates in my case would be, let's say, very useful. Rummaging in nete, found Smarty
, but in fact it is an engine. So, in principle, you can implement everything yourself. Found a couple of examples through ereg_replace()
and str_replace()
. But examples are too meager in material. Actually, the question is: how is this done, more specifically, and how, when using templates, do you get the necessary material in the templates?
2 answers
Php itself is a template engine. Just do not use logic in the template more than <? if : ?> <? else : ?> <? endif; ?>
<? if : ?> <? else : ?> <? endif; ?>
<? if : ?> <? else : ?> <? endif; ?>
and you can reduce the output to <?= $var; ?>
<?= $var; ?>
. Look at how serious frameworks are made ( Zend Framework
, Symfony
) - there native php
+ helpers are used in the templates, and there is no garbage.
- at 5 am something is too lazy to sit in the net, look for) can you link to the studio on the frameworks? - DemoriaN
The template engine will be able to write when you have to write it! It makes no sense to google in search of a template engine, since examples and ready-made solutions are dead, there is no use on a serious project with them! As for Smarty
- very weighty. Yes, and I personally do not give him the benefits! In order to create at least one’s own opinion a good template maker, Object-Oriented Programming (OOP) is necessary. You can begin to quench here! Classes and Objects For the first time, you can do the same ereg_replace()
and str_replace()
. He himself began to use it, the main thing is to understand the essence of the work, and then look for an objective replacement!
- oneereg - deprecated, forget about it slowly. - Sh4dow
- I have already forgotten, taken exclusively from the question) - Palmervan
- Well, approximately, I imagine that you cannot write it in a couple of evenings. Interested in the general structure, maybe there are good manuals for this case. Of course, you can take the same bb'shny forum and pick it up, but I really don't like to pick other people's creations, especially without comments. In fact, I now have about 200 .php files on the site, for every single moment, total .css, respectively. and God forbid, I think that I do not like the current template. We'll have to, well, if only to edit all these files ... - DemoriaN
- As an option, see how the mapping is implemented in the well-known frameworks ala
Zend
,Cake
etc. <br> And having figured out about how, what and where, just write your implementation. - Zowie
<?=cblock('news', 'main_template')?>
PS: Smarty is evil. If you do not have a load of ~ 3-4 business cards per day and you do not work with 2 layout designers who are familiar only with Smarty - he is not needed . - Sh4dow