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?

  • Do you need templates without php? ex .: <?=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
  • the problem is that I’m the only one writing the site, I have already changed the PCP code 3 times and changed the template 4 times .. thus, respectively, I had to re-write the whole structure, which is very tiring. poraskinuv brains on asphalt ... came to the conclusion that I want to make a separate brain, separately "design." so that in case of necessity it was not necessary to change everything, because of the need, for example, to change the site template. Well, something like this ... - DemoriaN
  • It is better to do as long as it turns out, atoms can be redone natsat times and hang so doing nothing! If a project is done only for itself and the student coder doesn’t stick his nose in there, then how about me ... what a beautiful code! But we ... the first time! And for the improvement you need to have at least something! “The first BMWs didn’t drive 350 km / h either ” - Palmervan
  • it's all clear, we have a project like it stopped ... started very actively, and six months later everything got up (for 2 years), now they paid for the domain again ... and so on and so on .. the web part of the project was hung up on me again, for the first couple of months I sat reading my code, the thought “God, how could I have done it?” elementary registration did not even check for the username in the database, changed the template again, rewriting a little more than half of the code ... I realized that it’s more if you don’t want. - DemoriaN

2 answers 2

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!

  • one
    ereg - 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