Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

drupal - How to quickly theme a view?

I've defined a view with the CCK and View 2 modules. I would like to quickly define a template specific to this view. Is there 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 which 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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...