我需要将信息从数据库打印到html模板,但我读过有最佳实践,而不仅仅是打印所需的html。有点模板填充物。 谢谢。
编辑:我发现框架Smarty,所以,从一个带有可变字段的html模板,我可以填写像这个$smarty->assign('htmlVar', $data);
的字段,然后加载它。
再次感谢。
我们可以使用DOMDocument::createElement和许多相关方法来构建一个可以输出的DOM。
此函数创建类DOMElement的新实例。除非与(例如)
DOMNode::appendChild()
一起插入,否则此节点不会显示在文档中。
Another alternative回应HTML的字符串,是使用类似的东西:
<?php if ( condition ): ?>
<p>This will be output</p>
<?php elseif ( other_condition ): ?>
<p>This will be output instead</p>
<?php else: ?>
<p>Or this</p>
<?php endif; ?>