Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By byenary on
Hi there,
I'd like to show/not show fields in a view depening on a condition (language)
I've found out I need to use the hook :
hook_views_pre_view
But can't find out how to show/hide fields using the hook.
Thx in advance!
Comments
Use a template suggestion and
Use a views template suggestion and then hide unnacessary fields in it.
That could be a solution
That could be a solution indeed, maybe its just easy'r then to create a sperate view for each language
/** * Implements
for Views 3:
Subscribed
Subscribed
Nice one, would you know how
Nice one, would you know how you can do exclude the field but only for some of the results? For example:
Good question.
Good question.
I've made a solution with the views_conditional module (drupal.org/project/views_conditional).
Have you found a code-based solution (which is better in my case)?
Old thread, but as i found it
Old thread, but as i found a simple solution :
Drupal 8
Nice, i could use the same logic in Drupal 8.
In drupal 8 below code works for me.
/**
* Implements hook_views_pre_render().
*/
function MODULENAME_views_pre_render(&$view) {
if ($view->name == 'VIEW_NAME' && $view->current_display == 'DISPLAY_NAME' && OTHER_CONDITIONS) {
$view->field['FIELD_NAME']->options['exclude'] = TRUE;
}
}
Drupal 8
Anyone can advise me how to
Anyone can advise me how to make a condition base on the views field? I want to get the views field value and assign create a condition with the value on the user profile.
Ex:
if (User Profile State == Views field state){
$view->field['field state']->options['exclude'] = TRUE;
}
else{
$view->field['field state']->options['exclude'] = FALSE;
}
For Drupal 8+:
For Drupal 8+: