Bilal Khan Posted November 15, 2021 Share Posted November 15, 2021 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 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted November 22, 2021 Share Posted November 22, 2021 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 . 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.