osCommerce / oscommerce2

osCommerce Online Merchant v2.x
http://www.oscommerce.com
MIT License
281 stars 222 forks source link

Template class and incoherent logic #644

Open tgely opened 5 years ago

tgely commented 5 years ago

Hi Community, :family_man_woman_girl_boy:

Although the base concept is professional not possible to build header tags, inner styles or scripts in HTLM header from content modules when build processes. For this problem the solution was paralell installing header_tag modules into the core. :collision: ?

There are some rocks before the required functionality. First obstruction is that the template content managment is critcal build after _templatetop.php. Lets see the probem in _productinfo.php https://github.com/osCommerce/oscommerce2/blob/de0e97d15d43ac6a9a6cfb2847134a82a0148f2b/catalog/includes/OSC/Sites/Shop/Templates/Sail/template_top.php#L5

<?php
  require($oscTemplate->getFile('template_top.php'));

  if ($product_exists === false) {
?>

<div class="contentContainer">
  <div class="contentText">
    <div class="alert alert-warning"><?php echo OSCOM::getDef('text_product_not_found'); ?></div>
  </div>
.
.
.

  <div class="row">
    <?php echo $oscTemplate->getContent('product_info'); ?>
  </div>

:gear: As we see this above logic is not reasonable to use template class as required. Not possible to inject header_tags. More logic if something like would be used below, when getContent() is above _templatetop.php and display content modules from class saved array:

<?php
  $oscTemplate->getContent('product_info');
  require($oscTemplate->getFile('template_top.php'));
?>
.
.
.
  <div class="row">
<?php
  if (isset($oscTemplate->_content['product_info']) && !empty($oscTemplate->_content['product_info'])) {
    foreach ($oscTemplate->_content['product_info'] as $value) {
      echo $value;
    }
  }
?>
  </div>

This logic ensure in all content module's execute() function to use oscTemplate->addBlock() for header_tags include scripts, css or inject inline codes into html header. https://github.com/osCommerce/oscommerce2/blob/de0e97d15d43ac6a9a6cfb2847134a82a0148f2b/catalog/includes/classes/osc_template.php#L73-L75

I dont understand why is not seriously used.

Thanks attentions