PDA

View Full Version : tpl variable in php



kimaweb
12-10-06, 11:21 PM
Hi everybody.

So I've been searching this forum for a loooong time now.

I could really use some help.

I wrote with matt earliery today and he said that it is posible to add you own php variable in the tpl files.

So i did this in viewinvoice to get it to show and ekstra field, but.. it dosnt work. Dos anyone have an idea of what i am doing wrong?

First i added this:

{php}
$moms = $total/5;
{/php}


then where i wanted to show the amount (20% of the total amount) i added this:

{php} echo $moms; {/php}

but it shows 0


Anyone whom can help me please


Sincerely Matt

MACscr
12-10-06, 11:23 PM
echo $total and see what you get. Most likely it will be 0

what exactly are you trying to do?

if total is a smarty variable, then just do

{math equation="x / 5" x=$total}

kimaweb
12-10-06, 11:26 PM
Yes, 0 i was..

but how can i fix it? there must be a way?

MACscr
12-10-06, 11:29 PM
heck, even {$total/5} might even work

kimaweb
12-10-06, 11:34 PM
Im really sad now.

That didnt work. It showed 0, but.. at least it did show something...

More ideas?

MACscr
12-10-06, 11:41 PM
both of my suggestions didnt work?

kimaweb
12-10-06, 11:47 PM
None of them worked.

a smarty what?

It is just the viewinvoice.tlp i am trying to and and ekstra fielnd in.

Here some of the code, so you can see what im doing:


<tr><td id="invoiceitemsheading"><div align="right">{$LANG.invoicescredit}</div></td><td id="invoiceitemsheading" align="center">{$credit}</td></tr>
<tr><td id="invoiceitemsheading"><div align="right">Moms </div></td>

{php}
$moms = $total/5;
{/php}

<td id="invoiceitemsheading" align="center">{php} echo $moms; {/php}</td>
</tr>

MACscr
12-10-06, 11:56 PM
right, dont try doing it with {php} tags, remove that completely and just try:

{$total/5}

or

{math equation="x / 5" x=$total}

kimaweb
12-11-06, 12:18 AM
With {math equation="x / 5" x=$total} it shows nothing.

With {$total/5} it shows 0

MACscr
12-11-06, 12:34 AM
what is your total normally?

kimaweb
12-11-06, 12:41 AM
Well, depends on what people are ordering. :-)

But on this invoice the total amount is 99

MACscr
12-11-06, 01:29 AM
there were a couple hurdles. The main one was that the $ was causing issues with the math. Here is a work around and does exactly what you wanted.


{php}
$total = $this->get_template_vars('total');
$newtotal = sprintf("%01.2f", ((str_replace('$','',$total)) / 5));
echo '$'.$newtotal;
{/php}

kimaweb
12-11-06, 09:05 AM
did you test that? coz it dosnt work here...?

MACscr
12-11-06, 05:56 PM
yep, works perfectly for me.

kimaweb
12-11-06, 06:12 PM
Maybe you have msn messenger? wanna help me? it would really be so nice..

MACscr
12-11-06, 06:26 PM
lol, scroll up, i have 3 different messengers listed above.

btw, i have/had no need for this code, i did it just for you out of the kindness of my heart. Merry Christmas =P

kimaweb
12-11-06, 06:30 PM
hehe, i did add you, but no ones there. :-)

I know, you do this to be nice, and im pleased!