Working W/ Variables Listed In 'aff_stats.html' (Smarty)

Discussion in 'Customization & add-ons' started by joelmon, Jun 14, 2008.

  1. joelmon

    joelmon New Member

    Joined:
    Oct 26, 2007
    Messages:
    8
    Hey,

    Is there a way to add (or any math function) 2 variables listed in a smarty template?

    I want to master the ability to manipulate these smarty html pages but I realize the rules don't apply as they do to pure PHP

    For instance, if you look at aff_stats.html, you will see 2 unique lines of code that display a value that arrives from a db call:

    Line #1: {$d.uniq|string_format:"%d"} // displays daily unique hits

    Line #2: {$d.raw|string_format:"%d"} // displays daily total hits

    Imagine I create another column on that page that is used to display the dividend between the 2 or the sum. How would I work that out within the smarty code?

    For instance, the new column would show in psuedo code

    PHP:
    <?php

    $ratio
    =$line 1 code $line 2 code;
    print(
    $ratio);

      
    ?>
  2. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    Within the template files you can do the math within smarty tags
    eg {$d.uniq / $d.raw}

    I've just done this to create a conversion ratio for the transactions / visitors for affiliate's display pages.
    [​IMG]

    David
  3. joelmon

    joelmon New Member

    Joined:
    Oct 26, 2007
    Messages:
    8
    Interesting. However, when I added a column in aff_stats.html
    (the section where you must click on the month to get monthly stats)

    I tried to type this within the column to provide a demo output

    {$d.uniq / $d.raw}

    and it provided this error:

    An Error has occured

    ERROR [256] Smarty error: [in aff_stats.html line 101]: syntax error: invalid attribute name: '/' (Smarty_Compiler.class.php, line 1497) in line 1102 of file /home/wwwulti/public_html/amember/smarty/Smarty.class.php

    Hrm...

    TY for the reply. Maybe I am missing something...I need to read up on smarty because I am sure it's much easier than I realize. But
    it's been a pain figuring out how to output a dividend between 2 values.
  4. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    Try removing the spaces:
    {$d.uniq/$d.raw}

    David
  5. joelmon

    joelmon New Member

    Joined:
    Oct 26, 2007
    Messages:
    8
    Ah, look at that. Thanks!

    Just one last q, if I may

    When there is a daily division between the 2, and the end result is 0, the
    error is:

    WARNING: Division by zero in line 134 of file %%101^%%1014743997^aff_stats.html.php

    How does one disable that for each record within the template?

    I really appreciate your time and will join your membership. I really appreciate your time as I love php but hate these template engines (for now)

    Thanks again. I'm going to bone up on the smarty tutorials so I can learn how to harness php with these.
  6. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    Check to make sure the number your dividing is more than zero
    {if $d.uniq > 0.0} stuff {/if}

    BTW- The affiliate template files to show the conversion (like in the image) are downloadable from my member's aMember hack forum.

    David
  7. joelmon

    joelmon New Member

    Joined:
    Oct 26, 2007
    Messages:
    8
    Ah, works. I just have to convert the string format. Beautiful (TY, again)

    I'll check out your hacks, no question. It's just interesting to see the logic with the html files as compared to PHP. I am used to doing this in php. Heck, it's funny because I can rebuild the entire thing in php but smarty templates...ha!

    I see, so if statement logic can work within it, just in a different way.

    I'll dig into how to work more into the php logic within smarty, but I have learned a lot today. I really appreciate your time.

Share This Page