Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: tpl variable in php

  1. #1
    Join Date
    Dec 2006
    Location
    Denmark
    Posts
    35

    Default tpl variable in php

    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

  2. #2
    Join Date
    May 2006
    Posts
    2,530

    Default

    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}

  3. #3
    Join Date
    Dec 2006
    Location
    Denmark
    Posts
    35

    Default

    Yes, 0 i was..

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

  4. #4
    Join Date
    May 2006
    Posts
    2,530

    Default

    heck, even {$total/5} might even work

  5. #5
    Join Date
    Dec 2006
    Location
    Denmark
    Posts
    35

    Default

    Im really sad now.

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

    More ideas?

  6. #6
    Join Date
    May 2006
    Posts
    2,530

    Default

    both of my suggestions didnt work?

  7. #7
    Join Date
    Dec 2006
    Location
    Denmark
    Posts
    35

    Default

    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>

  8. #8
    Join Date
    May 2006
    Posts
    2,530

    Default

    right, dont try doing it with {php} tags, remove that completely and just try:

    {$total/5}

    or

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

  9. #9
    Join Date
    Dec 2006
    Location
    Denmark
    Posts
    35

    Default

    With {math equation="x / 5" x=$total} it shows nothing.

    With {$total/5} it shows 0

  10. #10
    Join Date
    May 2006
    Posts
    2,530

    Default

    what is your total normally?

  11. #11
    Join Date
    Dec 2006
    Location
    Denmark
    Posts
    35

    Default

    Well, depends on what people are ordering.

    But on this invoice the total amount is 99

  12. #12
    Join Date
    May 2006
    Posts
    2,530

    Default

    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.

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

  13. #13
    Join Date
    Dec 2006
    Location
    Denmark
    Posts
    35

    Default

    did you test that? coz it dosnt work here...?

  14. #14
    Join Date
    May 2006
    Posts
    2,530

    Default

    yep, works perfectly for me.

  15. #15
    Join Date
    Dec 2006
    Location
    Denmark
    Posts
    35

    Default

    Maybe you have msn messenger? wanna help me? it would really be so nice..

Page 1 of 2 12 LastLast

Similar Threads

  1. How to use php variable code in html block? cart.php hosting package descriptions.
    By Sfed in forum Customisation & Integration Questions
    Replies: 0
    Last Post: 09-22-12, 12:05 PM
  2. Passing a variable to the tpl files
    By UmbraHosting in forum Customisation & Integration Questions
    Replies: 2
    Last Post: 03-16-09, 09:06 AM
  3. tpl file variable access
    By sLIVER in forum Customisation & Integration Questions
    Replies: 1
    Last Post: 12-12-07, 08:47 PM
  4. how to set global variable for smarty tpl file.
    By naveen3 in forum Customisation & Integration Questions
    Replies: 4
    Last Post: 04-18-07, 07:57 PM