Problem with math in smarty! - smarty

I'm trying to plus and multiply three values in my template file but smarty is messing with me
{assign var="x" value="`$smarty.get.pageID * $perPage`"}
{$x + $smarty.section.co.index_next}
How can I do that?!

sorry that was a silly question i solve it like this :
{if $smarty.get.pageID ne 1 }
{assign var="x" value=$smarty.get.pageID}
{math equation="(( x * y ) + z )" x=$x y=$perPage z=$smarty.section.co.index_next}
{else}
{$smarty.section.co.index_next}
{/if}

Related

Laravel having space output issue in blade file

I have Laravel code in Blade like this :
<span id="pk_dens" name="pk_dens" class="text-#if($productpages->pk_dens > 2.2 && $productpages->pk_dens < 3.3) success #else danger #endif">
{{$productpages->pk_dens}}%
</span>
So in class="text-#if($productpages->pk_dens > 2.2 && $productpages->pk_dens < 3.3) success #else danger #endif"
it will add space in class like text- danger and text- success so class not apply
so how can I avoid that spce in if else condition ?
Use ternary operator
<span id="pk_dens" name="pk_dens" class="text-{{ ($productpages->pk_dens > 2.2 && $productpages->pk_dens < 3.3) ? 'success' : 'danger' }}">
{{$productpages->pk_dens}}%
</span>
https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary
I think you are missing here is ? in ternary syntax and to remove space just remove all white spaces from the span tag and make it in just one line.
<span id="pk_dens" name="pk_dens" class="text-{{ ($productpages->pk_dens > 2.2 && $productpages->pk_dens < 3.3) ? 'success' : 'danger' }}">{{$productpages->pk_dens}}%</span>

Xpath text between tags

Any idea how i would get the text between 2 tags using Xpath code? specifically the 3, bd, 1, ba.
<p class="MuiTypography-root RoofCard__RoofCardNameStyled-niegej-8 hukPZu MuiTypography-body1" xpath="1">
<span class="NumberFormatWithStyle__NumberFormatStyled-sc-1yvv7lw-0 jVQRaZ inline-block md">$65,000</span></p>
**"3" == $0
" bd, " == $0
"1" == $0
" ba | " == $0**
<span class="NumberFormatWithStyle__NumberFormatStyled-sc-1yvv7lw-0 jVQRaZ inline-block md" xpath="1">926</span>
tried:
In fact from your sample that's a simple text() node after p:
//p/following-sibling::text()[1]
but of course you'll need to parse it. This will return almost that you need:
values = response.xpath('//p/following-sibling::text()[1]').re(r'"([^"]+)"')

Prestashop 1.6. How to check if product isPack in .tpl?

I want to check in theme (front) product.tpl file (PS 1.6.1.4) if state if product is Standard product or Pack of existing products
{if $product_type == Product::PTYPE_PACK} not working....
I want to return boolean.
use:
{if $packItems|#count > 0}
an example of using you can find it in product.tpl in the theme folder.
used in this way:
{if $packItems|#count > 0}
<div class="short_description_pack">
<h3>{l s='Pack content'}</h3>
{foreach from=$packItems item=packItem}
<div class="pack_content">
{$packItem.pack_quantity} x {$packItem.name|escape:'html':'UTF-8'}
<p>{$packItem.description_short}</p>
</div>
{/foreach}
</div>
{/if}
in addition, there is in a products object:
$product->id_pack_product_attribute = null
$product->cache_is_pack = 0
for non-pack products

Smarty check if date is between

i need check if smarty now date is equal or between my two dates.
If dates is the same months its work. But if:
Start = 19.01.2015 and
Stop = 1.02.2015 and
smarty now is 19.01.2015 it show no. Only if i change months it don't work
{if ($smarty.now|date_format:"%d.%m.%Y") >= ($value->getVariableValue('Start')) AND ($smarty.now|date_format:"%d.%m.%Y") <= ($value->getVariableValue('Stop'))}
yes
{else}
no
{/if}
try this i hope it will work :
Php file :
<?php
$start_date = "19.01.2015";
$end_date = "1.02.2015";
$smarty->assign('start', $start_date);
$smarty->assign('stop', $end_date);
$smarty->display("date.tpl");
?>
tpl file(date.tpl) :
<{if (($smarty.now|date_format:"%d.%m.%Y") >= ($start)) AND (($smarty.now|date_format:"%d.%m.%Y") <= ($stop)) }>
yes
{else}
no
{/if}

Smarty if statement with date?

If I have a smarty variable
{$test.date_created}
that displays a date in a smarty template, for example:
02/2/2012
On the smarty website, it says that you can display today's date with the following.
{$smarty.now|date_format:'%m/%d/%Y'}
How can I use it in an if statement to display a message when its 3 days old or more from today's date?
If its 3 days old or more, display "Old". If not, Display "New".
You can use strtotime() to get the timestamp corresponding to three days ago, and then compare this to the date of your message. For example, assuming $message is your message record and $message['date'] is the timestamp you have to check:
$isMessageOld = ($message['date'] <= strtotime('-3 days'));
$smarty->assign('isMessageOld', $isMessageOld);
And then, in your template:
{if $isMessageOld} ... {/if}
I'm not 100% sure, but you can also test it directly in Smarty. Assuming you have $message passed to Smarty:
{if $message.date <= strtotime('-3 days')} ... {/if}
You can easily check already passed date in smarty by using this $smarty.now
$smarty.now|date_format:"%Y%m%d"
Here is an example of cross the old(passed) date
<{foreach from=$meetings item=m}>
<{if $smarty.now|date_format:"%Y%m%d" <= $m.date|date_format:"%Y%m%d"}>
<tr>
<td><{counter}></td>
<td><{$m.title}> on </td>
<td><{$m.date}></td>
</tr>
<{else}>
<tr>
<td><strike><{counter}></strike></td>
<td><strike><{$m.title}> on </strike></td>
<td><strike><{$m.date}></strike></td>
</tr>
<{/if}>
<{/foreach}>
We need to create meeting list array in php and assign it in smarty
$meetings[0]['title'] = "Speech on Gandhi Janyanti";
$meetings[0]['date'] = "2-Oct-2011";
$meetings[1]['title'] = "Meet friend";
$meetings[1]['date'] = "10-Oct-2013";
$meetings[2]['title'] = "Goto USA";
$meetings[2]['date'] = "22-Oct-2013";
$meetings[3]['title'] = "Speech on Gandhi Janyanti";
$meetings[3]['date'] = "2-Oct-2014";
$meetings[4]['title'] = "Meeting with John";
$meetings[4]['date'] = "22-Oct-2014";
$meetings[5]['title'] = "Speech on Gandhi Janyanti";
$meetings[5]['date'] = "2-Oct-2015";
$meetings[6]['title'] = "Meeting with Uncle";
$meetings[6]['date'] = "22-Oct-2015";
$theme->assign("meetings",$meetings);
echo $theme->fetch("index.tpl");

Resources