Reputation: 1345
I have the following PHP function:
protected function getFieldRow($label, $value, $encode = true)
{
if (empty($value))
{
return '';
}
return FoxHtmlElem::create()->append(FoxHtmlElem::create('dt')->classes('field-title')->text(JFilterInput::getInstance()->clean($label)))->append(FoxHtmlElem::create('dd')->classes('field-content')->html($encode ? nl2br(FoxHtmlEncoder::encode(JFilterInput::getInstance()->clean($value))) : $value))->render();
}
Which outputs to a list of:
<dt class="field-title">Label</dt><dd class="field-content">Value</dd>
<dt class="field-title">Label</dt><dd class="field-content">Value</dd>
<dt class="field-title">Label</dt><dd class="field-content">Value</dd>
How can I change the function to add a Colon ":" in plain text within the output like so:
<dt class="field-title">Label : </dt><dd class="field-content">Value</dd>
<dt class="field-title">Label : </dt><dd class="field-content">Value</dd>
<dt class="field-title">Label : </dt><dd class="field-content">Value</dd>
Upvotes: -1
Views: 176
Reputation: 1577
If you were to place a colon there, it WOULD appear but outside of the rules and styling of the description list.
I assume you would want it within the label tag like so:
protected function getFieldRow($label, $value, $encode = true)
{
if (empty($value))
{
return '';
}
return FoxHtmlElem::create()
->append(FoxHtmlElem::create('dt')->classes('field-title')->text(JFilterInput::getInstance()->clean("{$label}:")))
->append(FoxHtmlElem::create('dd')->classes('field-content')->html($encode ? nl2br(FoxHtmlEncoder::encode(JFilterInput::getInstance()->clean($value))) : $value))
->render();
}
If you do want it the way you originally asked though, I'd guess at this being the solution (although google doesn't know what classes you are using and so neither do I so I cannot test it)
protected function getFieldRow($label, $value, $encode = true)
{
if (empty($value))
{
return '';
}
return FoxHtmlElem::create()
->append(FoxHtmlElem::create('dt')->classes('field-title')->text(JFilterInput::getInstance()->clean($label)))
->append(":")
->append(FoxHtmlElem::create('dd')->classes('field-content')->html($encode ? nl2br(FoxHtmlEncoder::encode(JFilterInput::getInstance()->clean($value))) : $value))
->render();
}
Upvotes: 1
Reputation:
Why don't you add it in alongside the Label like:
<dt class="field-title">Label :</dt>
You can do this by concatenating ':' with label;
$label .= " : ";
Hope this helps!
Upvotes: 1