简体   繁体   中英

How to use smarty code in PHP file?

I'm appending a table row to the HTML table in smarty template by using AJAX. It's working perfect for me except a small thing. I'm not able to integrate smarty code in this ajax response. Following is the AJAX response from PHP file.

echo "<tr id='reb$rebate_no'><td><input type='text' name='pack[]' value='' class='form-control' size='8'/></td>
      <td><input type='text' name='quantity[]' value='2' class='form-control' size='8'/></td>
      <td><input type='text' name='volume[]' value='750' class='form-control' size='8'/></td>
      <td><div class='btn-group'><select id='unit' name='units[]' class='form-control'><option value='' {if $data.id==''} selected='selected'{/if}>Select Unit</option>
      {foreach from=$all_volume_units item=units key=key}<option value='{$units.id}' {if $units.id == $data.units[$units]} selected='selected'{/if}>{$units.unit}</option>
      {/foreach}</select></div></td><td><input type='text' name='amount[]' value='3.00' class='form-control' size='9'/></td></tr>";

The above code is giving error. But I want to include the smarty code or to replace the smarty code by PHP code. How should I achieve this?

I think, smarty is not designed for such usage, because it first compiles the string into php code. However it is possible to use string resource, but whenever string is changed new php file is created. double quotes should not be used to enclose string, PHP will recognize words starting with dollar sign as variables.

more information on using string resources, is here; http://www.smarty.net/docs/en/resources.string.tpl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM