Jump to content

Calls to the database in .tpl with Conditionals and Product details


Recommended Posts

Hi guys, i'm new to Prestashop and really i'm not very used to work with Symfony.

I'm using the classic template and i did some modifications to the following .tpl files in order to split features in different columns.

  • /catalog/product.tpl
  • /catalog/_partials/product-details-tpl

I've archieved it by multipling sections inside product-details.tpl and filtering the results inside of each one with the following snippet of code.

<div class="tab-pane fade" id="product-details6" data-product="{$product.embedded_attributes|json_encode}" role="tabpanel">
  {block name='product_features'}
    {if $product.grouped_features}
      <section class="product-features">
        <dl class="data-sheet">
        {foreach from=$product.grouped_features item=feature}
          {if ($feature.id_feature == 44) || ($feature.id_feature == 323) || ($feature.id_feature == 325) || ($feature.id_feature == 326) || ($feature.id_feature == 327) || ($feature.id_feature == 328) || ($feature.id_feature == 329) || ($feature.id_feature == 330) || ($feature.id_feature == 331) || ($feature.id_feature == 332) || ($feature.id_feature == 333) || ($feature.id_feature == 334) || ($feature.id_feature == 3) || ($feature.id_feature == 3) || ($feature.id_feature == 335) || ($feature.id_feature == 336) || ($feature.id_feature == 337) || ($feature.id_feature == 346) || ($feature.id_feature == 347) || ($feature.id_feature == 348)}
            <dt class="name">{$feature.name}</dt>
            <dd class="value">{$feature.value|escape:'htmlall'|nl2br nofilter}</dd>
          {/if}
        {/foreach}
        </dl>
      </section>
    {/if}
  {/block}
</div>

Obiously i've multiplicated the Tabs too inside the product.tpl like this

                    <li class="nav-item">
                      <a
                        class="nav-link{if !$product.description} active{/if}"
                        data-toggle="tab"
                        href="#product-details"
                        role="tab"
                        aria-controls="product-details"
                        {if !$product.description} aria-selected="true"{/if}>{l s='Product Details' d='Shop.Theme.Catalog'}</a>
                    </li>

                    <li class="nav-item">
                      <a
                        class="nav-link"
                        data-toggle="tab"
                        href="#product-details2"
                        role="tab"
                        aria-controls="product-details2"
                        aria-selected="true">{l s='E. Caracteristicas' d='Shop.Theme.Catalog'}</a>
                    </li>
                    <li class="nav-item">
                      <a
                        class="nav-link"
                        data-toggle="tab"
                        href="#product-details3"
                        role="tab"
                        aria-controls="product-details3"
                        aria-selected="true">{l s='E. Material' d='Shop.Theme.Catalog'}</a>
                    </li>
                    <li class="nav-item">
                      <a
                        class="nav-link"
                        data-toggle="tab"
                        href="#product-details4"
                        role="tab"
                        aria-controls="product-details4"
                        aria-selected="true">{l s='E. Compatibilidades' d='Shop.Theme.Catalog'}</a>
                    </li>
                    <li class="nav-item">
                      <a
                        class="nav-link"
                        data-toggle="tab"
                        href="#product-details5"
                        role="tab"
                        aria-controls="product-details5"
                        aria-selected="true">{l s='E. Informacion Adicional' d='Shop.Theme.Catalog'}</a>
                    </li>

 

Now how can i put some kind of IF control in order to check if the realtive features ID are empties or not?

I've tried also to write PHP inside a tpl file but obviously it doesn't work.

Thanks you!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...