2

I want the user to be able to choose whether to show a description or not for each node in the view. Adding the filter only works on the entire object, I just want to show/hide one field. How can I achieve this?

2
  • 1
    what code have you tried? Take this question and strip "Drupal" from it. You have a listing and you want to toggle a <div> as shown or not-shown. Javascript can propbably do this. You probably want to look at the Form API, hook_form_alter() and the #states FAPI element in the Drupal API. Or, just just custom jQuery on the page ...
    – tenken
    Commented Mar 10, 2013 at 21:10
  • @Sergo, when you say you 'want the user to be able to choose' do you mean that you want to toggle between showing all description fields (where present) and hiding all description fields, using a toggle / dropdown akin to the normal Views exposed filters. Or do you mean that the user (who is editing the node) needs to be able to tick a box to make some text appear or not when the node is shown in a listing (my interpretation for the answer I've given). Or something else again?
    – Obliquely
    Commented Mar 11, 2013 at 0:27

2 Answers 2

12

You can do this with Views out of the box. No need for Views PHP here.

  1. Add your boolean field in Views. (This assumes the default boolean set up, i.e. 0 for not checked and 1 for checked.)

  2. Use the Key formatter - this isn't obvious, but I couldn't get it to work without this.

  3. Select REWRITE RESULTS and put the description you want in there. This can include tokens so you can grab material from other fields in the node if that's what you need.

  4. On NO RESULTS BEHAVIOR check all the boxes (Count the number 0 as empty, Hide if empty, Hide rewriting if empty)

0
0

You should be able to accomplish this with th Views PHP module.

Set up your view with the checkbox and description fields included but not visible. Then include a Global:PHP field, and under the field configuration put something like:

<?php
echo ($row->checkbox) ? $row->description : '';
?>

in the Display box.

1

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.