1

I have basic listing in a View. I can give styles, or unformatted text, provide a link, etc. However, I would need the listing to be a list of linked items, with the destination URL changing depending on context: language, type of user, etc. So I just retrieve the listing with a view, and in the template, I use views_get_view_result to print the fields I need and warp them with the necessary parameters (the dynamic URL, etc.). Is that a good approach or could this be achieve through the config of the View or with aid of another module (Context, Context Views, whatever...). Thanks!

1
  • its used to render the view result by calling "views_get_view_result" Here is a thread with additional ways of doing this, if you need the extra complexity / depth. drupal.org/node/951442 Commented Sep 2, 2015 at 7:48

2 Answers 2

1

Trying to give a reply to the question title:

you use views_get_view_result() when you need the result of a view inside your custom code. It works fine inside module or theme files.

For instance: you need to get a list of users inside your custom module. Instead of querying the database with db_query, yuo can build a Users View named a_list_of_users and get results with

    $res = views_get_view_result($name = "a_list_of_users", $display_id = "default");

Any additional parameters will be passed as arguments.

I love this function!

0

To get the correct translated link you need to use Internationalization Views module which translates the links based on the current language. The Path Translation module is also helpful.

Many things can be done by Views directly, but if you really need to customize the view results don't use views_get_view_result. You need to use Theme Information template pages of the view under the Advanced section,

enter image description here

These preprocess template pages are called before displaying the view and they are called to build the result of the view. It has three different levels and each one is used to theme its relevant output.

For example views-view-fields--VIEWNAME.tpl.php is used to theme the fields of the view and every field is available in this template file.

The THEME_preprocess_views_view_fields(&$variables) function in the template.php file of your theme folder is another available option. you can set or get some attributes of the view (like field views of the view.)

These options bring you lot's of choices, as an example you can define one view template for multiple views, you can theme individual fields or theme a row or theme the entire view (the above mentioned three levels) .

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