0

我尝试按照本文档中的描述在 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>
4

1 回答 1

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;
}
于 2013-01-05T10:25:04.377 回答