Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Prestashop1.7 : "un-group" Product Features

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Frameworks
View previous topic :: View next topic  
Author Message
taniacr
Smarty n00b


Joined: 28 Nov 2018
Posts: 3

PostPosted: Mon Jun 24, 2019 4:45 pm    Post subject: Prestashop1.7 : "un-group" Product Features Reply with quote

Hi,

In product-details.tpl the features, when grouped, are printed inside a single <dd>

For example:
Code:

<dl>
   <dt>FEATURE</dt>
   <dd>Value1 Value2 Value3</dd>
</dl>


I want to print the following:
Code:

<dl>
   <dt>FEATURE</dt>
   <dd>
       <span title="value1">Value1</span>
       <span title="value2">Value2</span>
       <span title="value2">Value3</span>
   </dd>
</dl>



This is the original code.. tried what I can but no avail
Code:

  {block name='product_features'}
    {if $product.grouped_features}
      <section>
        <h3>{l s='Data sheet' d='Shop.Theme.Catalog'}</h3>
        <dl>
          {foreach from=$product.grouped_features item=feature}
            <dt>{$feature.name}</dt>
            <dd>{$feature.value|escape:'htmlall'|nl2br nofilter}</dd>
          {/foreach}
        </dl>
      </section>
    {/if}
  {/block}


Tried the following that, obviously doesn't work:

Code:

 {if $product.grouped_features}
      <section>
        <h3>{l s='Data sheet' d='Shop.Theme.Catalog'}</h3>
        <dl>
          {foreach from=$product.grouped_features item=feature}
            <dt>{$feature.name}</dt>
            <dd>{foreach $feature.value}<span title="{$feature.value|replace:' ':'_'}">{$feature.value|escape:'htmlall'|nl2br nofilter}</span>{/foreach}</dd>
          {/foreach}
        </dl>
      </section>
    {/if}


Most grateful for any help possible.
Thank you
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Mon Jun 24, 2019 8:26 pm    Post subject: Reply with quote

I would like to see what the actual value of $product.grouped_features.

To do this, at the bottom of this template, add:
Code:
{debug}

When the browser shows this page, there will be a popup. In the popup is a list of all the variables and their contents. Find $product, and then examine the grouped_features array.

The {foreach} is splitting each element into a 'name' and 'value'. If the 'value' is a simple string containing all of "Value1 Value2 Value3", then some editing of the source PHP code that is assembling this array needs to be worked on.

If, however, "Value1" and "Value2" and "Value3" are single words (and always will be single words), we may be able to split those words on the space into another template variable and {foreach} across that.
Back to top
View user's profile Send private message
taniacr
Smarty n00b


Joined: 28 Nov 2018
Posts: 3

PostPosted: Tue Jun 25, 2019 11:30 am    Post subject: Reply with quote

Hi, thank you for your answer.

I debugged the template and in the $product line there is only the following:

$product

Array (2)
value => PrestaShop\PrestaShop\Adapter\Presenter\Product\ProductLazyArray Object (0)
scope => "Smarty object"

Tried the following code too:

Code:

{block name='product_features'}
    {if $product.grouped_features}
        <section>
            <h3>{l s='Data sheet' d='Shop.Theme.Catalog'}</h3>
            <dl>
                {foreach from=$product.grouped_features item=feature}
                    <dt>{$feature.name}</dt>
                    {assign var=detail_feature value=" "|explode:$feature.value}
                    <dd>
                        {foreach from=$detail_feature item=det_feature}
                            <span title="{$det_feature|escape:'htmlall'|nl2br nofilter}">{$det_feature|escape:'htmlall'|nl2br nofilter}</span>
                        {/foreach}
                    </dd>
                {/foreach}
            </dl>
        </section>
    {/if}
{/block}


But splits the words. For example is the value is: Value One it prints <span title="Value">Value</span> <span title="One">One</span>
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Frameworks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP