How to disable field output depending on the return from another field?

In my view, there are fields that I prefer to hide depending on the value of another field. I am looking for ways to do this in code or otherwise, but without including the php filter.

+3
source share
3 answers

I do not know which version of Views you are using. I can’t remember if it was possible to rewrite the output in V2, but I suppose it is. In V3, he is there, expecting you to use it.

Rewriting the output accepts any HTML code, and you can use replacements from the returned request. I'm not sure if you can use PHP there, maybe you can, but I never tried. In any case, let's say you have field_fooboth field_bar, and that both are some selection options or flags or some other selection options that have key-value pairs in the database (for example, 1 | foo, 2 | bar, etc.) ,.

In this situation, you should have four options:

[field_foo_value]
[field_foo_value_raw]
[field_bar_value]
[field_bar_value_raw]

(they will probably be named differently; I cannot recall the exact naming convention). You can rewrite the output of the bar field as follows:

<span class="visibility-[field_foo_value_raw]">[field_bar_value]</span>

Then, assuming the possible keys for "foo" are 1 and 2, you can write CSS:

span.visibility-1 { display: inline; }
span.visibility-2 { display: none; }

PHP , , , HTML. , , .

+1

hook_form_alter hook_form_FORM_ID_alter, views_exposed_form. CTools ' . (. views--form.tpl.php), , , , / .

0

Source: https://habr.com/ru/post/1788352/


All Articles