Hey guys,
For the love of all things holy I can't figure out how to add two numbers together in smarty. I've checked the manual, there's no main section, if it's in there, it's probably lost within some section.
I've tried {2+3}, {(2+3)}.
What i'm trying to do is add a number of days to a date. I have a list of objects, and a member of the object is a date (start date). These "things" expire within 45 days, so what I need to do is show the expiration date.
My object does not have a expireDate member and I don't want to change my array of objects to an array of array and add the expiration date on the PHP side, too resource intensive.
Any clue?
Here's the TPL code: - <ol>
-
{foreach from=$resultVOList item="postVO"}
-
<li><a href="#" class="postLink">{$postVO->title}</a> — {$postVO->location} — <b> ${$postVO->price} </b>
-
<br /><b>Author:</b> {$postVO->author}
-
<br /><b>ISBN:</b> {$postVO->ISBN}
-
<br /><b>Created:</b> {$postVO->datePosted|date_format}
-
<br /><b>Expires:</b> {2+3}
-
<div class="right"> <a href="#">[ Edit ]</a> - <a href="#">[ Delete ]</a></div>
-
<div class="hrzln" ></div></li>
-
{foreachelse}
-
<li>No Book Posts, click on New Post to add a book for sale</li>
-
{/foreach}
-
-
</ol>
Thanks everyone,
Dan
3 20732
Couldn't find it, so I added a modified for Smarty here's the code if anybody wants it:
modifier.addDays.php (put this in plugin dir) -
-
<?php
-
/**
-
* Smarty plugin
-
* @package Smarty
-
* @subpackage plugins
-
*/
-
-
-
/**
-
* Smarty custom plugin to add a integer to a date and returns the date in US format mm/dd/yyyy
-
*
-
* Type: modifier<br>
-
* Name: addDays<br>
-
* Purpose: adds a specified number days to a date
-
* @author Dana Murad
-
* @param string
-
* @param integer
-
* @return string
-
*/
-
function smarty_modifier_addDays($string,$numOfDays)
-
{
-
list($month,$day,$year) = explode("/",$string);
-
$date = mktime(0,0,0,$month,$day+$numOfDays,$year);
-
return date("m/d/Y",$date);
-
}
-
-
?>
-
-
-
so my code now looks like: -
<ol>
-
{foreach from=$resultVOList item="postVO"}
-
<li><a href="#" class="postLink">{$postVO->title}</a> — {$postVO->location} — <b> ${$postVO->price} </b>
-
<br /><b>Author:</b> {$postVO->author}
-
<br /><b>ISBN:</b> {$postVO->ISBN}
-
<br /><b>Created:</b> {$postVO->datePosted|date_format}
-
<br /><b>Expires:</b> {$postVO->datePosted|addDays:$smarty.const.EXPIRE_DAYS|date_format}
-
<div class="right"> <a href="#">[ Edit ]</a> - <a href="#">[ Delete ]</a></div>
-
<div class="hrzln" ></div></li>
-
{foreachelse}
-
<li>No Book Posts, click on New Post to add a book for sale</li>
-
{/foreach}
-
-
</ol>
-
Hope it helps somebody, Suggestions welcome,
Dan
Wow, that seems strange that they wouldn't have something so simple like {2+3}.. I had a scan around for you, and found something called 'math equation'. I think you do it like so: {math equation="1 + 1"}. I'm sure you'll be able to find something about it on google.
Thanks Markus.
I'd like to point out that I found something interesting about the addition (and I assume other operations).
Whitespace matters. For example: {$num1+$num2} works but {$num1 + $num2} does not.
The plus sign has to be attached to the numbers your adding or else you'll get an error or only the first number is shown.
Since most developers code with PHP and HTML, thus disregard whitespace, I just wanted to point that out.
Dan
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Daan |
last post by:
Hello all,
I'm having a little problem with Smarty. Getting it to work in a simple
case went fine, but now I have the following situation:
/
/smarty
/templates
template.tpl
/templates_c
|
by: Richard |
last post by:
I need help. I have a smarty based program that I am modifying. I
have a smarty template file that consists of smarty and HTML.
I need to integrate some PHP database calls into it. My problem...
|
by: M |
last post by:
Hi Folks,
I am trying to install Smarty using PHP 5 on a Windows XP PC using IIS
v6
The following PHP File:
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
|
by: Matt |
last post by:
geez, i've done this a million times, you'd think i could get it right.
uploading to production server for a new site, and part of the head.inc
that starts everything up looks like this:
echo...
|
by: Andy |
last post by:
Hi,
Are 1 through 4 defined behaviors in C?
unsigned short i;
unsigned long li; /* 32-bit wide */
1. i = 65535 + 3;
2. i = 1 - 3;
3. li = (unsigned long)0xFFFFFFFF + 3;
4. li = 1...
|
by: Conrad |
last post by:
Hi, I'm very new to Smarty Template Engine and I'm using PHP 5.0.4 on
the Windows XP Professional platform and I have the following question:
When I change the 7th line of the script to use a...
|
by: Paul |
last post by:
Why is the addition here adding the number as a string but the subtraction
works fine?
function boxchange(box) {
iv= dbform.ut.value
if (box.checked == true) {
iv = iv - box.value
}
else {...
|
by: muler |
last post by:
hi all,
After reading this excerpt from "The C# Programming Language", (By
Anders) I tried to check it out. Unfortunately, I'm getting compile
errors.
Can anyone illustrate this with an...
|
by: ajaymohank |
last post by:
hello friends.......... i am new to smarty. can anyone please tell me how to get the value from a dynamically generated checkbox using smarty. this is the code i used... here i am generating 10...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |