Hi, I'm not sure if I can do this in my news summary template. I want to use the value in a field in a math equation. Is this the correct syntax for capturing the value in the row? Thank you!
{math equation="x - y" x=$smarty.now y=$entry->fields.row1->value assign=years} {$years|date_format:"%Y"}
Math in a news summary template
-
- Forum Members
- Posts: 142
- Joined: Fri Jun 17, 2011 12:22 am
-
- Forum Members
- Posts: 142
- Joined: Fri Jun 17, 2011 12:22 am
SOLVED: Math in a news summary template
I did figure this one out. In the summary template I added:
{assign var="date" value=$smarty.now|date_format:'%Y'}
{capture assign="year"}{$entry->fields.row3->value}{/capture}
{assign var="startyear" value=$date - $year}
{assign var="totalyear" value=$date - $startyear}
then in the code:
<b>Total Years:</b> {$totalyear}<br />
<b>Start Year:</b> {$startyear|string_format:"%d"}
{assign var="date" value=$smarty.now|date_format:'%Y'}
{capture assign="year"}{$entry->fields.row3->value}{/capture}
{assign var="startyear" value=$date - $year}
{assign var="totalyear" value=$date - $startyear}
then in the code:
<b>Total Years:</b> {$totalyear}<br />
<b>Start Year:</b> {$startyear|string_format:"%d"}
Re: Math in a news summary template
A bit shorter:
Code: Select all
{$date = $smarty.now|date_format:'%Y'}
{$year = $entry->fields.row3->value}
{$startyear = $date - $year}
{$totalyear = $date - $startyear}
Total Years: {$totalyear}
Start Year: {$startyear|string_format:'%d'}
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
-
- Forum Members
- Posts: 142
- Joined: Fri Jun 17, 2011 12:22 am
Re: Math in a news summary template
Thank you so much showing me that!
Re: Math in a news summary template
Though seems your original approach was close:
This looks funny to me:
Perhaps I'm missing some details but to me it's the same as:
It seems that $totalyear == $year == $entry->fields.row3->value
Code: Select all
{math equation="x - y" x=$smarty.now|date_format:"%Y" y=$entry->fields.row3->value assign=startyear}
Total Years: {$entry->fields.row3->value}
Start Year: {$startyear}
Code: Select all
{assign var="startyear" value=$date - $year}
{assign var="totalyear" value=$date - $startyear}
Code: Select all
10 - 3 = 7
10 - 7 = 3
-
- Forum Members
- Posts: 142
- Joined: Fri Jun 17, 2011 12:22 am
Re: Math in a news summary template
I set up our staff directory in the News Module because it could be templated easily, and staff members could update the listings themselves.
Originally, when I populated the content, the template read "Years worked here:" with the numeric value. In proofing, I pointed out that this would need to be updated every year, and somebody would need to remember to do that. I wanted to add math so that the values would auto update.
Then it was change to: "At this office since:" with the year. I didn't want to go in and update each persons entry, so again, I wanted to use math to calculate this change.
In either case, I simplified my example for when I posted the solution I came up with. It is really cool how math can be applied to templates for these situations.
Thanks again!
Originally, when I populated the content, the template read "Years worked here:" with the numeric value. In proofing, I pointed out that this would need to be updated every year, and somebody would need to remember to do that. I wanted to add math so that the values would auto update.
Then it was change to: "At this office since:" with the year. I didn't want to go in and update each persons entry, so again, I wanted to use math to calculate this change.
In either case, I simplified my example for when I posted the solution I came up with. It is really cool how math can be applied to templates for these situations.
Thanks again!