我有以下PHP函数,它从附加的值"渲染"输出:
protected function getFieldRow($label, $value, $encode = true)
{
if (empty($value))
{
return '';
}
return FoxHtmlElem::create()->append(FoxHtmlElem::create('div')->classes('field-title')->text(JFilterInput::getInstance()->clean($label .= ": ")))->append(FoxHtmlElem::create('div')->classes('field-content')->html($encode ? nl2br(FoxHtmlEncoder::encode(JFilterInput::getInstance()->clean($value))) : $value))->render();
}
输出到如下列表:
<div class="field-title">Label : </div><div class="field-content">Value</div>
<div class="field-title">Label : </div><div class="field-content">Value</div>
<div class="field-title">Label : </div><div class="field-content">Value</div>
我如何更改函数,以便它将两个附加的值组合在同一div 中,如下所示:
<div class="field-content">Label : Value</div>
<div class="field-content">Label : Value</div>
<div class="field-content">Label : Value</div>
谢谢。
看起来你想这样做:
<?php
return FoxHtmlElem::create()
->append(FoxHtmlElem::create('div')
->classes('field-content')
->html( JFilterInput::getInstance()->clean($label .= ": "). ($encode ? nl2br(FoxHtmlEncoder::encode(JFilterInput::getInstance()->clean($value))) : $value)))->render();
只需将标签变量移动到 HTML 方法中,而不是创建单独的div。