|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
taniacr Smarty n00b
Joined: 28 Nov 2018 Posts: 3
|
Posted: Mon Jun 24, 2019 4:45 pm Post subject: Prestashop1.7 : "un-group" Product Features |
|
|
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 |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Mon Jun 24, 2019 8:26 pm Post subject: |
|
|
I would like to see what the actual value of $product.grouped_features.
To do this, at the bottom of this template, add:
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 |
|
taniacr Smarty n00b
Joined: 28 Nov 2018 Posts: 3
|
Posted: Tue Jun 25, 2019 11:30 am Post subject: |
|
|
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 |
|
|
|
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
|