문제

Hi I'm a Drupal newbie and am really struggling with best practices for this CMS. Right now I am trying to use the Panels 3 Module to create the pages of my website with custom layouts that I have created. What I can't seem to wrap my head around is the ridiculous amount of excessive markup that's coming from panels as well as each individual template in the drupal install (node.tpl, field functions, region.tpl etc etc). I have some very elaborate website designs that I need to create and the html that is being generated from the Drupal templates and field functions is literally making my job impossible. I am used to wordpress where I can simply make a database query example(wp_query()), grab the values that I need and display them in any markup that I want. What am I missing here in Drupal? Am I really supposed to overwrite 7 template files all the way down to the field level in Drupal to get some clean markup? What am I missing here?

도움이 되었습니까?

해결책

In your own themes template.php you can implement the theme_field() hook to style the output for each field. Similar hooks exist for regions, blocks, node, page. Just copy the default code and modify it.

Here is an example how I usually simplify the output for e.g. a content slider:

function yourtheme_field__field_slidertext(&$variables) {
  $output = '';
  foreach ($variables['items'] as $delta => $item) {
    $output .= '<li class="slide">' . drupal_render($item) . '</li>';
  }
  $output = '<ul class="slider">' . $output . '</ul>';
  return $output;
}

If you want an easier way to strip down markup and choose some common output options for fields have a look at the Drupal Fences module.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top