简体   繁体   中英

Joomla Custom Fields Output for Joomla article

I tried to implement Custom field in Joomla article as described in this documentation : http://docs.joomla.org/Adding_custom_fields_to_the_article_component

But the output is wrapped in one table output

<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>

How can I divide the output so I the out put can be like this :

<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>

You'll have to change onContentPrepare function as per your requirement.

Try this-

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM