Jump to content

tpl variable in php


kimaweb

Recommended Posts

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated