Joomla的Joomla Custom Fields输出文章

时间:2013-01-05 09:01:37

标签: php joomla

我尝试在Joomla文章中实现Custom字段,如本文档中所述: 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>

1 个答案:

答案 0 :(得分:0)

您必须根据自己的要求更改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;
}