I would like to print the array of a specific View within a template, so I can then access each specific field and theme as I wish. The view I am using will only be outputting one row. All my attempts seem to be returning 'previously declared' errors.

Your help is appreciated. Thanks

  • there is a $view variable which contains the entire View object available in most if not all Views templates, and $views->result contains the data in the row, so that should contain what you are looking for
    – Jimajamma
    May 2 '13 at 3:02
  • Please show your code, it'll make things much easier to debug
    – Clive
    May 2 '13 at 9:02
  • Cool, I managed to drill down to the field I want to render: <pre>print render($view->result[0]->field_field_media_image[0]['rendered']['#item']['uri'])</pre> This outputs the objects content fine within the Views template, however my final objective is to have this single object render within my homepage template. Currently, the views template block renders within a page block. Is this even the best method to render a specific view object within a page?
    – jayboss
    May 2 '13 at 19:38

There are a few steps involved with applying a template to view. But thankfully they are all fairly simple.

I found one of the most helpful tutorials was this one, which goes through the process. I think this process should give you sufficient control over the theme for each field.

I'm not sure why you might be getting the 'previously declared' errors though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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