0

I have a file views-view--MyView--block-2.tpl.php

there is no $fields variable, it doesn't exist.

if I do a foreach($view->field as $v=>$f) and print both $v will show me all my fields in that view and display

  • created
  • title
  • field_op_author_nid
  • field_main_image_fid
  • field_teaser_value
  • comment_count

but $f is always empty.

How do I access my fields?

[EDIT] Ok, let me clarify. the .tpl file I have renders just fine. the markup I have in that file shows up. The issue is that I cannot access the fields I set up in the view and displaye. I tried changing the filename to include -fields- and I indeed did get the $fields variable. This looks to be exactly the same as the $view variable that I had before, which I don't know how to get data out of. I can see the fields I need in there but the var_dump($fields( or $ view)) is about 20 pages long and every example I have seen has been just using $fields["fieldname"], which does not work.

Am I just maybe doing this wrong entirely? What is the best way to set these up, is it to have multiple tpl files, one for each field and row?

4 Answers 4

0

By the time the processes reach the views-view.tpl.php level, the Fields have already been rendered and are not available for further manipulation.

I would need more information about what you are actually trying to do, as well as which versions of Drupal and Views you are using, in order to suggest a specific solution. For example: are you trying to manipulate the data within the fields, or just wrap the field content in different HTML?

Either way, you can do a lot of manipulation of the field data and wrapping HTML within the Views UI, using the "Rewrite Results" option within each field's settings, or you can get even more control over the wrapping HTML by utilizing the Semantic Views module.

3
  • Drupal 6, OpenPublish, Views2. OpenPublish Theme is my base theme Here's what I am trying to accomplish: I have a new view, lets call it MyView. In MyView I have 2 Displays, both of type Block lets call them Block_1 and Block_2 I want to wrap the fields in the block with my own markup so that they render differently. I currently have .tpl files for this but I cannot figure out how to access the fields I added to the View. I want to do this right, but I'm not experienced with Drupal so I don't really know any best practices or anything (sorry I can't add line breaks?)
    – Jerzakie
    Commented Feb 7, 2012 at 1:18
  • I would highly recommend the Semantic Views module - it lets you easily alter the HTML that wraps many different Views components from within the Views UI.
    – sheena_d
    Commented Feb 7, 2012 at 2:00
  • Semantic Views is EXACTLY what I need! Thank you so much!
    – Jerzakie
    Commented Feb 7, 2012 at 3:09
0

I THINK you need to be using views-view-fields--myview--block-2.tpl.php to access $fields.

0

Simple concept is go to theme information and check the tpl file names in the field you want and choose the unique file name from there and create the tpl file.
Now click on the first file name which will give you the basic code, copy that in your tpl file now in comment you will see all four variable try with $row and print the whole array and find all your other fields as well.

0

If you are not sure about the file name for your template you can use the theme developer module. You can just point and click on in your browser to find the right theme and template functions.

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.