How to quickly theme a view?

2019-01-10 01:16发布

I've defined a view with the CCK and View 2 modules. I would like to quickly define a template specific to this view. Any tutorial or information on this? What are the files I need to modify?


Here are my findings: (Edited)

In fact there are two ways to theme a view : the "field" way and the "node" way. In "edit View", you can choose "Row style: Node", or "Row style: Fields".

  • with the "Node" way, you can create a node-contentname.tpl.php which will be called for each node in the view. You'll have access to your cck field values with $field_name[0]['value']. (edit2) You can use node-view-viewname.tpl.php wich will be only called for each node displayed from this view.
  • with the "Field" way, you add a views-view-field--viewname--field-name-value.tpl.php for each field you want to theme individually.

Thanks to previous responses, I've used the following tools :

  • In the 'Basic Settings' block, the 'Theme: Information' to see all the different templates you can modify.
  • The Devel module's "Theme developer" to quickly find the field variable names.
  • View 2 documentation, especially the "Using Theme" page.

10条回答
叛逆
2楼-- · 2019-01-10 01:55

for me block-views-myViewName-myBlockId.tpl.php works

查看更多
仙女界的扛把子
3楼-- · 2019-01-10 01:55

If you want to do quick Drupal development with a lot of drag-and-drop, the Display Suite module def. is a something you should use: http://drupal.org/project/ds

查看更多
爷的心禁止访问
4楼-- · 2019-01-10 01:57

A quick way to find the template files you can create and modify for a view in Views 2.0 is to:

  1. Edit the view
  2. Select the style (e.g. page, block, default)
  3. In the 'Basic Settings' block click on 'Theme: Information' to see all the different templates you can modify.
查看更多
Melony?
5楼-- · 2019-01-10 02:00

According to me there are two ways to do it:

Programatic Way:

  1. Go to edit view.
  2. Select page/block style.
  3. Go to 'Basic Settings' and click on 'Theme: Information' to see all the different templates you can modify.
  4. Add the html you want to theme and print the variables of the view wherever needed

Configuration Update: Using the Display suiteThe Display suite provides us an option to place your labels inline or above and add even to hide them. Custom classes to each of the view's elements can be added too. Advanced options include:

  • Exportables
  • Add your own custom fields in the backend or in your code
  • Add custom layouts in your theme (D7 only)
  • Change labels, add styles or override field settings (semantic fields).
  • Full integration with Views and Panels
  • Extend the power of your layouts by installing Field Group
  • Optimal performance with Object cache (D6) or Entity cache (D7) integration
查看更多
来,给爷笑一个
6楼-- · 2019-01-10 02:01

In fact there are two ways to theme a view : the "field" way and the "node" way. In "edit View", you can choose "Row style: Node", or "Row style: Fields".

  • with the "Node" way, you can create a node-contentname.tpl.php wich will be called for each node in the view. You'll have access to your cck field values with $field_name[0]['value']
  • with the "Field" way, you add a views-view-field--viewname--field-name-value.tpl.php for each field you want to theme individually.

Thanks to previous responses, I've used the following tools :

  • In the 'Basic Settings' block, the 'Theme: Information' to see all the different templates you can modify.
  • The Devel module's "Theme developer" to quickly find the field variable names.
  • View 2 documentation, especially the "Using Theme" page.
查看更多
我想做一个坏孩纸
7楼-- · 2019-01-10 02:02

The Devel module's "Theme developer" feature is handy for seeing what template files Drupal is looking for when it goes to theme something. See the screenshot on that page for an example.

查看更多
登录 后发表回答