Pair view fields content on a Drupal 7 view quick howto
*Valid for: Drupal 7, Views *
I have two multiple text fields on a Drupal 7 content type.
I want to display those fields paired by delta in a view. Here the code I used in my module named mymodule.module.
function mymodule_views_pre_render(&$view) { // pair field contents if ($view->name == 'my_view_name' && $view->current_display == 'my_view_display') { foreach ($view->result as $key => $res) { if ($res->field_data_field_youtube_url_delta != $res->field_data_field_youtube_url_description_delta) { unset($view->result[$key]); } } } }
Thanks to hook_views_pre_render().
I use this piece of code to pair Youtube URLs and plain text description for a JSON output generated via Views Datasource.
Remember to disallow multiple values when adding these fields to your view or you’ll get incoherent results.
https://web.archive.org/web/20130125000000*/http://drupal.org/project/views_datasource (https://web.archive.org)
Response: 20 (Success), text/gemini
| Original URL | gemini://chirale.org/2013-01-25_965.gmi |
|---|---|
| Status Code | 20 (Success) |
| Content-Type | text/gemini; charset=utf-8 |