PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, June 28, 2022

[FIXED] How display the first element of a list ? Smarty, Prestashop module

 June 28, 2022     php, prestashop, smarty     No comments   

Issue

I'm trying to change a view in a Prestashop Module. I would like to display just the first one case of a list.

Here, is the original list:

 {if count($tax_details)>0 && $use_taxes}
        <br />
        <br />
        <table cellpadding="3">
            <thead>
                <tr style="color:#FFFFFF; background-color: #4D4D4D; font-weight:bold; padding:2px;">
                    <th style="width: 40%;">{l s='TAX DETAILS' mod='opartdevis'}</th>
                    <th style="width: 20%;">{l s='Tax rate' mod='opartdevis'}</th>
                    <th style="width: 20%;">{l s='Total without tax' mod='opartdevis'}</th>
                    <th style="width: 20%;text-align: right;">{l s='Total tax' mod='opartdevis'}</th>
                </tr>
            </thead>
            {foreach $tax_details as $tax}
                <tr>
                    <td style="width: 40%;">{$tax.prefix|escape:'htmlall':'UTF-8'}</td>
                    <td style="width: 20%;">{$tax.name|escape:'htmlall':'UTF-8'}</td>
                    <td style="width: 20%;">{Tools::displayPrice($tax.total_ht)}</td>
                    <td style="width: 20%;text-align: right;">{Tools::displayPrice($tax.total_tax)}</td>
                </tr>
            {/foreach}
        </table>
    {/if}

It display this : enter image description here

And I would like to display just this number in yellow on another place. enter image description here

This is my code (it situated on the same page than the original list):

 {if count($tax_details)>0}
                    <tr>
                        <td colspan="7" style="text-align:right;">
                            Total éco taxes : 
                        </td>
                        <td colspan="1" style="text-align:right;">
                            <span id="total_price_remiseincl">
                                {Tools::displayPrice($tax_details[0].total_tax)}
                            </span>
                        </td>
                    </tr>
                {/if}

I have this error: enter image description here

I tried many ways to write it, but I don't find how to do.

Could you help me pls ? I'm new with Smarty.

Thanks in advance Malaury


Solution

You need to set up a loop again

{assign 't' '0'}
{foreach $tax_details as $tax}
    {if $t === '0'}
      {Tools::displayPrice($tax.total_tax)}
      {assign 't' '1'}
    {/if}
{/foreach} 


Answered By - Richard
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing