How good is this piece of code? if you don't like it, what would you change?

<h3 class="margin-top-minus-10 font-24"><span class="tour-icon"></span>Tours To Uzbekistan</h3> <?php $current_tour_category = FALSE; ?> <?php foreach ($tours as $tour) : ?> <?php if ($tour['tour_category_name'] != $current_tour_category) : ?> <?php $current_tour_category = $tour['tour_category_name']; ?> <div class="middle-seperator"></div>> <h5 class="tour-category-name"><?=$tour['tour_category_name']?></h5> <?php endif; ?> <!-- TOUR ITEM START --> <div class="tour-item in-category"> <?php if ( ! empty($tour['picture']) AND file_exists('uploads/tours/'.$tour['picture'])) : ?> <img src="<?=base_url()?>uploads/tours/<?=$tour['picture']?>" alt="" /> <?php else : ?> <img src="<?=base_url()?>uploads/no-picture.jpg" alt="" /> <?php endif; ?> <h5><?=$tour['name']?></h5> <?php if ( ! empty($tour['quote'])) : ?> <blockquote><?=$tour['quote']?></blockquote> <?php else : ?> <blockquote><?=character_limiter(strip_tags($tour['text']), 150)?></blockquote> <?php endif; ?> <div class="tour-item-footer"> <div class="days"><?=lang('days')?> <?=$tour['days']?></div> <div class="nights"><?=lang('nights')?> <?=$tour['nights']?></div> <div class="reviews"><a href="#"><?=lang('reviews')?>: <?=$tour['reviews_count']?></a></div> <div class="pdf"><a href="<?=base_url()?>uploads/tours/pdf/<?=$tour['pdf']?>"><?=lang('download_in_pdf')?></a></div> </div><!-- .tour-item-footer --> <div class="costs"><span><?=lang('from')?></span> $<?=$tour['price']?></div> </div><!-- .tour-item --> <!-- TOUR ITEM END --> <?php endforeach; ?> 

It is closed due to the fact that it is necessary to reformulate the question so that it is possible to give an objectively correct answer by the participants aleksandr barakin , Regent , ixSci , pavlofff , dlarchikov Jul 19 '15 at 7:23 .

The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • @Palmervan, for the future - delete enough your comments. Removing others is bad practice. - Sh4dow
  • 2
    Normal view. What is there to change? - Vitaly Kustov

2 answers 2

I would use the template engine because my html and php has my watery eyes. I'm not talking about multi-type Smarty - no, something simple, allowing you to separate the logic from the presentation. I use my simple template engine for this and am happy as an elephant.

  • How is the blue elephant? :) And where is the logic there? I see one cycle and three if / else) No, here I will not arise, at least there is a practical use. Che, I get to the second day of all somehow aggressively. Pardonte, it itself ._. - Sh4dow
  • one
    The logic is separated from the presentation by the programmer and not by the template engine. If we are talking about PHP - I see no reason to write extra magic over the native implementation, PHP already has all the necessary properties of the template engine. There is practically no hash in the good code of the template, and if there is a place loaded with a code, they are beautifully divided and commented out in detail. And here it does not matter - a template with or without a template engine, the problem of devil-may-care attitude and the lack of brains is not a sieve =) PS: all the above stated just a modest IMHO - Zowie
  • @ Sh4dow, for me, logic is all that does not begin with <?= . The cycle and the three conditions also do not contribute to the understanding of the pattern. @AlexWindHope, I said: "install the template engine - it will separate everything"? Sorry, did not want to be misleading. =) In general, I answered the question "what would I improve." So: I would remove the control structures from the template to make it clearer. That's all. =) - ling
  • @ling - it looks really like this =) - Zowie

The last century :) I do not like when the generation of HTML occurs using PHP. Now, if PHP had generated JSON, and JS generated code based on them, it would be great :)

  • And what about performance? I think more time will go) - FreelancerUz
  • one
    Apart from Google, this heresy has never been seen. Generate html on the client - ad and pogibel. At least one argument in defense of this practice? Against: - client performance (the browser cannot render on the fly and distribute the load) - impossibility of caching the finished code - perversion with shielding - difficulty editing @FreelancerUz if you are not in a big company with full separation of code and html - do not use smarti. It simply does not make sense. - Sh4dow
  • one
    Vkontakte has the same policy of page formation. By the way, a very weighty argument: -80% load - performance on the client (the browser cannot render on the fly and distribute the load), okay? Take the same QOOXDOO, or ExtJS. They are well able to work on the client and they have excellent performance :) - the impossibility of caching the finished code Okay :) And what prevents to cache data from which JSON will be molded? - perverts with shielding Op, what? - the difficulty of editing figasse. None Is it possible to make a JSON problem from an array or an object? - Stanislav Komar
  • one
    - you must first wait for all the data, and then render. Browser optimization multiplied by zero. You first collect the data with the code, then parse it with the code, then compile the document with the code and then it is rendered. - nothing hinders data caching, and it is impossible to cache a ready-made executable file - all sorts, with inline-js in particular. Did not collide?) - from what array? editing a template is more difficult. And here you have no layout designer does not help. So the arguments in favor will be, except that "it's cool and stylish"? By the way, I'm not sure, but IMHO search engines will not like it either. - Sh4dow
  • one
    In general, for a regular website of the company or the home page of Vasi Pupkin, this, naturally, is not necessary. No one says that this can not be done, just won ~ = 0. To a greater extent it is suitable for RIA applications, or for sites with a sexy user-friendly UI and a bunch of buns. By the way - from an unobvious plus, if the server communicates exclusively with JSON, it is much easier to write an application under the device's mob, since There is no need to rewrite the server, but this, of course, is a specific feature. - Zowie