I have a view block that I'd like to customize a fair bit, so I'm trying to make a custom view template for the block that I can mess around with on the field level. The custom template registers fine (I can add arbitrary text to it and whatnot) - but how can I render the individual fields in that template per row?

For example, if I have a view called 'news' with the custom template views-view--news-block.tpl.php and that view has 4 fields: title, date, body and author lets say, how can I output that in my custom template like:

(repeat for each row)
[output title]
[output date]
[output body]
[output author]

I think I'm ok with finding the field names, but I'm not sure how to render them properly in the template, as well as how to do a (for each row) loop code-wise in Backdrop.  

Closest thing I could find on the forums went without a solution at: https://forum.backdropcms.org/forum/how-render-individual-fields-view-wi...

Any help or pointers to a good reference much appreciated!

Comments

@greenstick - I am not sure if I'm am understanding your problem entirely, but I have a few ideas that might be helpful.

1) Are you using the "theme debug" setting in the devel module?
https://api.backdropcms.org/documentation/theme-debug-mode

This setting will insert template suggestions in the source code for your page. You can see which template is rendering the content along with suggested file names it you want to override that theme template.

2) Are you familiar with "views rewrite." I often use the "rewrite" feature in views to overwrite the markup/format for a specific field or to rewrite the entire row. I'm not sure if this would be useful in your use case. If you need more information about how to use views rewrite, ask (or Google it, it works the same as it does in Drupal 7). 

You can use the "rewrite" feature to make very major changes in the format of the output of your view.

You can "rewrite" specific fields OR you can add several fields to a view, exclude them from the display, then add a custom text field and rewrite all the fields in whatever order you like.

3) Are you aware that views provides information for the field templates it uses along with suggested titles if you wish to create field templates to override them. For example, to override the title field within my test view I can copy: (views-view-field.tpl.php) and rename it (views-view-field--test--page--title.tpl.php)

To find these template names, look under the "Other" section of your view configuration page and click on "theme information."

Hopefully, at least one of these ideas will be helpful to you. None of what I have shared is specific to Backdrop CMS, it's all inherited from Drupal 7. If you need more details on any particular suggestion, let us know.

Thanks for the detailed reply stpaultim, it's been a while but yes I have some under standing of the templates to override (though I appreciate the reminder,) and it probably can be dealt with various ways.  

As it turns out, the individual fields aren't available in at upper hierarchy of the multiple views templates as they're not used there quite yet.

In my particular case I was trying to get at them in views-view--news-block.tpl.php, but I had to drill down a couple of templates and create a views-view-fields--news.tpl.php to override views-view-fields.tpl.php before I could get at them individually.  At this level I can use:

<?php print $fields['title']->content; ?>  (replace 'title' with the whichever field is needed) and it outputs just fine.

For any future reference I believe this template varies depending on the output type selected for your view,  I'm using 'fields' but you probably need to edit views-view-table.tpl.php for a 'table' output, views-view-list.tpl.php for a 'list', etc. etc.

Thanks again for the help!