Jump to content

Template issue


Marcus

Recommended Posts

lol .... yes right ...

 

what i mean

 

{php}

$query

$result

while {

if .... echo "<div>{$LANG.TAGanything}</div>";

else

echo "<div>{$LANG.TAGanythingelse}</div>";

}

{/php}

 

The purpose behind templating is to separate the code and design. You should perform the query in the primary php script file, stored in the whmcs root, store the results in an array, and then pass the array to smarty for use in the template file.

 

Here's an example of what I threw together real quick to make use of the testimonials we had stored up in AWBS, once we converted to WHMCS (after creating a simple table and pulling the data over from AWBS):

 

testimonials.php in whmcs root:

 

<?php 

require("dbconnect.php"); 
require("includes/functions.php"); 

$pagetitle = "Testimonials";
$pageicon = "images/support/order.gif";
$breadcrumbnav='<a href="index.php">'.$_LANG['globalsystemname'].'</a> > <a href="testimonials.php">Testimonials</a>'; 

require("init.php"); 

$testimonials_array = array();
$queryString = 'select * from tbltestimonials where status = 1';
$query = mysql_query($queryString);
while ($row = mysql_fetch_array($query, MYSQL_ASSOC)) {
       array_push($testimonials_array, $row);
} 
$smarty->assign('testimonials', $testimonials_array);

# Define the template filename to be used without the .tpl extension
$templatefile = "testimonials"; 

include("display.php"); 

?>

 

testimonials.tpl in template directory:

 

<p>Here are some of the unsolicited compliments we've received from our valued customers:</p>
{foreach from=$testimonials key=id item=i}
       <div style="border: 1px dotted #ccc; margin-top: 5px; padding: 10px; background-color:#ffefd5;">
       <div>{$i.testimonial}</div><br/>
       <div align="right">(received from {$i.sig1} of <a href="http://www.{$i.sig2}">{$i.sig2}</a>)</div>
       </div>
{/foreach}

 

The results look like this. (I haven't yet made the page public 'cause I need to remove the silly slashes from the output. I haven't had time to look and see if they're in the database records or being output by php. I'll probably paginate the results at some point as well.)

Link to comment
Share on other sites

  • 2 months later...

It took me a while to find a solution to this for a different project, but if you want to use template vars inside {php} or {include_php} tags, use extract($this->_tpl_vars) to extract the vars from the Smarty scope to the method scope!

{$variable}

{php}
extract($this->_tpl_vars);

echo $variable;
{/php}

 

I hope this helps if someone comes across this and needs it.

Link to comment
Share on other sites

any ideea how to get this working? it's from viewinvoice.tpl.

 

{php}

 

$item_price = $this->get_template_vars('invoiceitem.amount');

 

echo $item_price;

 

{/php}

 

i can't get the output for item price.

 

i think it has something to do with foreach but i don't know how to do it.

 

can you please help?

Link to comment
Share on other sites

  • 3 weeks later...
It took me a while to find a solution to this for a different project, but if you want to use template vars inside {php} or {include_php} tags, use extract($this->_tpl_vars) to extract the vars from the Smarty scope to the method scope!

{$variable}

{php}
extract($this->_tpl_vars);

echo $variable;
{/php}

 

I hope this helps if someone comes across this and needs it.

 

Excellent, worked for me. I was trying to get $account.domain array variable to resolve in the php portion. That code did the trick. THANKS !

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