Jump to content

Recommended Posts

As we have <<<HTML HTML in report client_statement.php, may i please know how to use PHP loop inside this tag ? we want to put all the products in drop down using php loop but unable to add php code inside <<<HTML HTML

Share this post


Link to post
Share on other sites

I don't think it supports logic but rather just output there.    One option off the top is to use a variable to store the content in and  breakout to do the loops and output to the same string.  So for example:

$HTML = <<<HTML 
               <p>some html</p><table>
  HTML;
  foreach($items as $item)
  {
      $HTML .= <<<HTML 
                      <tr><td>{$item}</td></tr>
	     HTML;
  }

return $HTML; 

(I rarely use <<< so just doing by what i recall and have seen recently in some modules )

Or just do what I do and have smarty deal with all the view stuff and have it fetch the template and return it instead of displaying.  


function fetchTemplateContents($template)
{
  $file = __DIR__ . "/templates/$template.tpl";
  $smarty = new \Smarty();
  $smarty->assign("some_items", $items);
  $HTML = $smarty->fetch($file);
  return $HTML; 
}

NOTES: it only has the variables you feed it -- no language overrides or standard merges unless you give it.  Template file needs to be absolute path and not a relative path -- thus the usage of __DIR__ to get your in to the current script's running directory .

Share this post


Link to post
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