Marcus Posted January 11, 2008 Share Posted January 11, 2008 Hi there, in one of my template files, i have an MySQL / php statement like this: {php} $query ..... {/php} Is there any way to use smarty / language tags inside this ? marcus 0 Quote Link to comment Share on other sites More sharing options...
minadreapta Posted January 11, 2008 Share Posted January 11, 2008 this is already a smarty tag.... 0 Quote Link to comment Share on other sites More sharing options...
Marcus Posted January 11, 2008 Author Share Posted January 11, 2008 lol .... yes right ... what i mean {php} $query $result while { if .... echo "<div>{$LANG.TAGanything}</div>"; else echo "<div>{$LANG.TAGanythingelse}</div>"; } {/php} 0 Quote Link to comment Share on other sites More sharing options...
Troy Posted January 11, 2008 Share Posted January 11, 2008 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.) 0 Quote Link to comment Share on other sites More sharing options...
Marcus Posted January 11, 2008 Author Share Posted January 11, 2008 Troy, cut off these days - yes - you're completly right, put it in a file ... ! thx a lot marcus 0 Quote Link to comment Share on other sites More sharing options...
Brett Posted March 12, 2008 Share Posted March 12, 2008 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. 0 Quote Link to comment Share on other sites More sharing options...
minadreapta Posted March 12, 2008 Share Posted March 12, 2008 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? 0 Quote Link to comment Share on other sites More sharing options...
Brett Posted March 12, 2008 Share Posted March 12, 2008 It would be like this - {php} extract($this->_tpl_vars); echo $item_price; {/php} 0 Quote Link to comment Share on other sites More sharing options...
minadreapta Posted March 12, 2008 Share Posted March 12, 2008 it doesn't seem to work this way, it just outputs nothing. 0 Quote Link to comment Share on other sites More sharing options...
Brett Posted March 12, 2008 Share Posted March 12, 2008 Ok, what is it that you are trying to accomplish? Most things can be done through smarty. 0 Quote Link to comment Share on other sites More sharing options...
minadreapta Posted March 12, 2008 Share Posted March 12, 2008 i just solved it, i had to put the php definition between the {foreach} brackets thanks. 0 Quote Link to comment Share on other sites More sharing options...
cyberneticos Posted March 28, 2008 Share Posted March 28, 2008 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 ! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.