我尝试在Joomla文章中实现自定义字段,如本文档所述:http://docs.joomla.org/Adding_custom_fields_to_the_article_component
但是输出被封装在一个表输出
<div class="rating"><table><tbody>
<tr class="row0">
<td>Texture</td>
<td>Rough and Chuncky</td>
</tr>
<tr class="row1">
<td>Temperatur</td>
<td>10</td>
</tr>
<tr class="row0">
<td>Taste</td>
<td>Sweet and Sour</td>
</tr>
</tbody></table></div>
我如何划分输出,使输出可以像这样:
<div class="wrapper">
<div class="div-texture-Title">Texture</div>
<div class="div-texture-content">Rough and Chuncky</div>
<div class="div-temperature-title">Temperatur</div>
<div class="div-temperature-content">10</div>
<div class="div-taste-title">Taste</div>
<div class="div-taste-content">Sweet and Sour</div>
</div>
您必须根据您的要求更改onContentPrepare
功能。
试试这个,
public function onContentPrepare($context, &$article, &$params, $page = 0)
{
if (!isset($article->rating) || !count($article->rating))
return;
// add extra css for table
$doc = JFactory::getDocument();
$doc->addStyleSheet(JURI::base(true).'/plugins/content/rating/rating/rating.css');
$output= '';
foreach ($article->rating as $attr => $value) {
$output .= '<div class="div-'.$attr.'-Title>'.$attr.'</div>';
$output .= '<div class="div-'.$attr.'-content>'.$value.'</div>';
}
// wrap table in a classed <div>
$suffix = $this->params->get('ratingclass_sfx', 'rating');
$html = '<div class="'.$suffix.'">'.(string)$output .'</div>';
$article->text = $html.$article->text;
}