i have categories and subs and i want draw every category with sub in td. i write this code but it draw all category with sub in one td. what is the problem? thank you
{section name=catsubs loop=$arrClientsCategorySub}
<td width="28" height="26" align="center" style="background-image:url(images/categorycolor.png); background-repeat:no-repeat; background-color:{$arrClientsCategorySub[catsubs].color}">
{section name=catsub2 loop=$arrClientsCategorySub[catsubs].arrsubCompanies}
<a id="ict-font-inner5sub" href="categoriescompanies.php?categoryid={$arrClientsCategorySub[catsubs].arrsubCompanies[catsub2].catsubid}">{$arrClientsCategorySub[catsubs].arrsubCompanies[catsub2].catsubnumber}</a>
{/section}
</td>
<td width="5"></td>
{/section}
I think your <td> code needs to go one {section} deeper to go around every subcateogry. Try this:
{section name=catsubs loop=$arrClientsCategorySub}
{section name=catsub2 loop=$arrClientsCategorySub[catsubs].arrsubCompanies}
<td width="28" height="26" align="center" style="background-image:url(images/categorycolor.png); background-repeat:no-repeat; background-color:{$arrClientsCategorySub[catsubs].color}">
<a id="ict-font-inner5sub" href="categoriescompanies.php?categoryid={$arrClientsCategorySub[catsubs].arrsubCompanies[catsub2].catsubid}">{$arrClientsCategorySub[catsubs].arrsubCompanies[catsub2].catsubnumber}</a>
</td>
{/section}
<td width="5"></td>
{/section}
Also, your code will be a lot more efficient and lightweight if your <td> was assigned a styled class instead of all that code in the long style tag.
Related
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 :
And I would like to display just this number in yellow on another place.
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:
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
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}
Alternatively, you can use the 'first' properly like below. (docs)
In your foreach, use,
{if $smarty.foreach.tax_details.first}
<tr>
<td colspan="3"></td>
<td style="width: 20%;text-align: right;">
{Tools::displayPrice($tax.total_tax)}
</td>
</tr>
{/if}
Hi I'm making this HTML email and thanks to the good old Outlook 07 that adds a really nice page break I kinda have to change my logic. Currently my html looks something like this:
<table>
<tr> //I want for every 6th element to create a new <tr>
<td>
<table>
{foreach from=$data.elements item=element name=elements}
{if $smarty.foreach.elements.iteration is odd}
<tr>
<td>
{/if}
<table align="{if $smarty.foreach.elements.iteration is odd}left{else}right{/if}">
Some content
</table>
{if $smarty.foreach.elements.iteration is odd}
<table align="left" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" height="40" style="font-size:1px; line-height:1px; mso-line-height-rule: exactly;"> </td>
</tr>
</table>
{else}
</td>
</tr>
{/if}
{/foreach}
</table>
</td>
</tr>
</table>
Right now after the 6th element it creates this page break so I want is when I have let's say 12 elements each six to have their own table row with table inside.
The following code should work for you:
<table>
{foreach from=$data.elements item=element name=elements}
{if $smarty.foreach.elements.iteration mod 6 eq 1}
<tr>
<td>
<table>
{/if}
{if $smarty.foreach.elements.iteration is odd}
<tr>
<td>
{/if}
<table align="{if $smarty.foreach.elements.iteration is odd}left{else}right{/if}">
Some content
</table>
{if $smarty.foreach.elements.iteration is odd}
<table align="left" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" height="40" style="font-size:1px; line-height:1px; mso-line-height-rule: exactly;"> </td>
</tr>
</table>
{else}
</td>
</tr>
{/if}
{if $smarty.foreach.elements.iteration mod 6 eq 0 or $smarty.foreach.elements.last}
</table>
</td>
</tr>
{/if}
{/foreach}
</table>
but because of many tables I cannot check it for sure. You could also look at Break UL tag after 'n' times in while-loop where I answered how to do the same in PHP.
I'm is using PHP smarty templater. I need to create even odd row highlighting.
Please, send me example how to do that.
also I have variable:
$smarty.foreach.product.index
For this kind of situation smarty has method called {cycle}
<table>
{foreach $products as $product}
<tr class="{cycle values="odd,even"}">
<td>{$product.name}</td>
</tr>
{/foreach}
</table>
The result for this will be:
<table>
<tr class="odd">
<td>1st product</td>
</tr>
<tr class="even">
<td>2nd product</td>
</tr>
<tr class="odd">
<td>3rd product</td>
</tr>
</table>
In you stylesheet file define properties for odd and even lines like this:
tr.even td{background: #CCCCCC;}
tr.odd td{background: #EFEFEF;}
<table>
{foreach key=i item=row from=$items}
<tr{if $i%2==1} bgcolor=#e4e4e4{/if}><td>{$i}</td></tr>
{/foreach}
</table>
{section name=myloop start=0 loop=10 step=1}
<tr class="{if $smarty.section.myloop.index is even}tr_even{else}tr_odd{/if}"><td>{$smarty.section.myloop.index}</td></tr>
{/section}
I am working on a site that isn't SEO friendly. Specifically, the header.tpl is inserted automatically into every page, with no option to change it based on the content of the page. I.e., whether category = Bathroom or category = Kitchen, etc.
So I need an if/else command, but having trouble figuring it out in this instance, plus the change that goes along with it.
The code on the portfolio_category.php page is as follows, and what needs to change based on vf_category is parts/header.tpl (I can create Bathroomheader.tpl, Kitchensheader.tpl, etc so that relevant tpl has the relevant Title and Description tags for the page).
<?php
$vc_root_friendly = '.';
$vc_root_site = '.';
include_once("$vc_root_site/config.php");
include_once("$vc_includes_folder/IT.php");
$template_body = new HTML_Template_IT();
$template_body->loadTemplateFile("tpl_portfolio_category.html");
include_once("$vc_includes_folder/images.php");
if(!isset($_REQUEST['vf_category'])){
header("location:portfolio.php");
die();
}
//Show header
$template_header = new HTML_Template_IT();
$template_header->loadTemplateFile("parts/header.tpl",true,false);
$template_body->setVariable('header', $template_header->get());
//Show footer
$template_footer = new HTML_Template_IT();
$template_footer->loadTemplateFile("parts/footer.tpl",true,false);
$template_body->setVariable('footer', $template_footer->get());
$template_body->setVariable("image_category", $_REQUEST['vf_category']);
//Select photos for this category
etc.
Complicating things there is another page referenced in the code above:
tpl_portfolio_category.html
And this page too has its own header.tpl include:
<? include_once 'parts/header.tpl'; ?>
{header}
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td class="main"><h1><span class="firstLetter">{image_category}</span></h1>
<p>
</p>
<table height="89" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="7"> </td>
</tr>
<!-- BEGIN block_thumb -->
<tr>
<td width='180' height="120" background="./images/thumb-bg.gif"> <div
align="center">{thumb1}</div></td>
<td width="10"> </td>
<td width='180' background="./images/thumb-bg.gif"> <div align="center">{thumb2}
</div></td>
<td width="10"> </td>
<td width='180' background="./images/thumb-bg.gif"> <div align="center">{thumb3}
</div></td>
<td width="10"> </td>
<td width='180' background="./images/thumb-bg.gif"> <div align="center">{thumb4}
</div></td>
</tr>
<tr valign="bottom">
<td height="3"></td>
<td height="3"></td>
<td height="3"></td>
<td height="3"></td>
<td height="3"></td>
<td height="3"></td>
<td height="3"></td>
</tr>
<!-- END block_thumb -->
</table>
<br>
<img src="images/spacer.gif"></td>
</tr>
</table>
{footer}
Any guidance would be appreciated! I'm just trying to get parts/header.tpl to change to parts/Bathroomheader.tpl or parts/Kitchenheader.tpl based on the vf_category pulled from the database. But it's driving me nuts.
Thanks in advance,
Gary
there are a few ways to do this, but in order to minimize the number of files you're changing, I suggest that you:
a) Pull the variable from the database and assign it to smarty, on your first php file, for both the header and body:
//Assuming you have retrieved $vf_category from your database;
$template_header->setVariable('vf_category', $vf_category);
$template_body->setVariable('vf_category', $vf_category);
b) Edit your file header.tpl and append the following code at the top:
{if 'vf_category' == 'some_value'}
{include file="parts/Kitchenheader.tpl"};
{elseif 'vf_category' == 'other_value'}
{include file="parts/Bathroomheader.tpl"};
{else}
//the rest of the header.tpl code goes here
{/if}
I have a question regarding smarty templates, I'm using PHP and Smarty in order to generate pages. I would like to somehow count or determine first and last row of table. So I can set different CSS for first and last TR or leave it as it is, if it's only 1 TR.
Hope it makes sense what im after. Thanks in advance.
<table class="table-paddings-2" cellspacing="0" cellpadding="0">
<tr>
<th class="table-gray-th-noborder">Search Type</th>
<th class="table-gray-th-noborder">Average Turnaround Time</th>
</tr>
{foreach key=obk item=row from=$report}
<tr>
<td class="td-border-top-only text-align-left">{$row.SearchName}</td>
<td class="td-border-top-only text-align-left">{$row.tt}</td>
</tr>
{/foreach}
</table>
Documentation is your friend: http://www.smarty.net/docsv2/en/language.function.foreach.tpl
Examples 7.12, 7.13:
{* show LATEST on the first item, otherwise the id *}
<table>
{foreach from=$items key=myId item=i name=foo}
<tr>
<td>{if $smarty.foreach.foo.first}LATEST{else}{$myId}{/if}</td>
<td>{$i.label}</td>
</tr>
{/foreach}
</table>