2

I've defined a view with the CCK and Views modules. I have two ways for printing the result:

  1. As node content
  2. As fields content

If I choose node content, I need to choose the view mode, which by default allows to choose between teaser, and rss (among others). How do I create a new custom view mode?

If I choose fields content, I see the following data, under theme information.

  • Display output: views-view.tpl.php, views-view--frontpage.tpl.php, views-view--default.tpl.php, views-view--default.tpl.php, views-view--page.tpl.php, views-view--frontpage--page.tpl.php

  • Style output: views-view-unformatted.tpl.php, views-view-unformatted--frontpage.tpl.php, views-view-unformatted--default.tpl.php, views-view-unformatted--default.tpl.php, views-view-unformatted--page.tpl.php, views-view-unformatted--frontpage--page.tpl.php

  • Row style output: views-view-fields.tpl.php, views-view-fields--frontpage.tpl.php, views-view-fields--default.tpl.php, views-view-fields--default.tpl.php, views-view-fields--page.tpl.php, views-view-fields--frontpage--page.tpl.php

How do I create a custom theme for printing the result using the fields method?

Edit1: i create new view mode with Chapabu answer.(create a custom build mode you can use Entity view modes)

now i see this result in front page : Image Link

now, this print default content with default html/css.in act, i need custom content default for my theme. Example : i dont need to print date and author content! i need to print image(Thumbs), Summary and content type. in html/css i need to list content in <ul><li></li></ul>Or Any Div or Span ... (custom html/CSS) How To Edit This HTML/CSS?

I Think Fields Method Better For My result. This Is TRUE? If YES, How To?

EDIT2: Example Of my Need Conetnt And CSS/HTML:

I need to design this block(in act example: article promoted front page Or last Article Or Last News ...) for show in vertical news ticker using jquery and css. this jquery plugin need to custom html/css:

 <h1>Latest News</h1>
<div class="newsTicker"> 
<ul>
<li><img class="Thumbs" src="" alt="">news item 1</li>
<li><img class="Thumbs" src="" alt="">news item 2</li>
<li><img class="Thumbs" src="" alt="">news item 3</li>
<li><img class="Thumbs" src="" alt="">news item 4</li>
<li><img class="Thumbs" src="" alt="">news item 5</li>
<li><img class="Thumbs" src="" alt="">news item 6</li>
<li><img class="Thumbs" src="" alt="">news item 7</li>
<li><img class="Thumbs" src="" alt="">news item 8</li>
</ul>
</div>

now, I need a custom content and html/css design views block for this.

8
  • Hello, and welcome to Drupal Answers. What do you mean by, "create new custom view node theme"?
    – avpaderno
    Commented Nov 30, 2012 at 12:15
  • 1
    To create a custom build mode you can use Entity view modes
    – Chapabu
    Commented Nov 30, 2012 at 12:23
  • @kiamlaluno:Hello, Thanks. I Edit My Question. my mean is: drupal have default view mode i.e: Teaser, RSS, search index, Tokens ... . now i need to add new(onother view mode theme) view mode for print result in node method.
    – Eric Float
    Commented Nov 30, 2012 at 12:24
  • I'm really sorry, but I this question makes ZERO sense. There are bits and pieces that do, but I don't see and way of getting a sensible question from this. Perhaps you could edit it further and try to get your end requirements across more succinctly.
    – Chapabu
    Commented Nov 30, 2012 at 17:33
  • @Chapabu: I thank you for your efforts to fix the problem and question. I add edit2 in my question. please see this.
    – Eric Float
    Commented Nov 30, 2012 at 20:43

4 Answers 4

0

When you're not satisfied with the existing view modes you could create your own using either your own tiny plugin (see ready code) or use Display Suite. The new view mode will appear in Views UI for selecting.

I'd recommend however the true theming technique by using Views and fields. There you have more flexibility and control over the markup. You can do many things using Views UI (such as turning off the wrapper markup, linking a field to its content, overwriting some attributes, etc.) When you find out you cannot do something in Views UI this might be a reason for using a .tpl.php file at one of the output levels - in your case the style or row variants would be your friends)

It's recommendable that you watch some Views tutorials, such as NodeOne's Taming the Beast series or by Mustardseed Media (even if for Views 2 only) to get the idea how to tailor Views output to your needs.

Hope this helps.

0

You can use Entity view modes to create new view modes for your entities without writing any code.

The Drupal 7 successor to Build modes which will allow administrators to define custom view modes for entities. Custom entities are added to the entity registry via hook_entity_info_alter() so they are available to any code that uses entity_get_info() to provide a list of view modes for an entity. This includes node and user reference fields, Views, etc.

1
  • I'm really confused. i test your methods and edit my question. you see my problem? can you help me with any tuts or step by step docs?
    – Eric Float
    Commented Nov 30, 2012 at 17:17
0

There are a few ways to theme a view in drupal. AS you said before you can output the view as 'node content' or as 'fields'. If you select 'node content', drupal will get the parameters for this content type as you config them in the content type menu (admin/structure/types/manage/{your-content-type}/display). If you select 'fields' you have to add every field you want to be displayed in the view and config it's output in the fields section of the view. There you can select if you want labels, the widget or the markup for the field.

With this you can configure the HTML output, I don't know if you mean css when you ask about theming.

The template files are for advanced output and just clicking in the views UI you'll get options to configure almost everything.

0

Creating custom entity view modes or themeing the view is quiet an overkill for your intention.

To massage views' HTML output to your example, consider using the fences module to customize html tags for wrappers, labels and field content.

In your case:

  1. Use the HTML list format, and show fields.
  2. Add the image and text fields without labels.
  3. For each field, under "STYLE SETTINGS", check "Customize field and label wrapper HTML", and select "- None -".

You'll get 90% of the structure you want, the rest is just tweaking.

For more advanced customization:

  1. Exclude the 2 fields, and add a third field of type "Custom text".
  2. In the custom text field, enter your more complex HTML structure, and use string replacement tokens to inject the field values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.