I'd like to implement Views that conditionally show or hide item listings of content nodes to the current User based on:
(1) value(s) in the current User's profile and
(2) value(s) in the profile of the author of each item and
(3) value(s) in each content node itself.

A good example would be a classified ad system that enabled advertisers to specify that a given ad be shown only to users whose profiles meet a set of specific criteria.

For example: A Drupal site with User Accounts with custom fields to capture each user's age, height, and hair, and a Content Type for advertisements with the same fields.

The challenge is how to construct a View that supports a use case like the following: Users who will look at the View:
= David is a bald, 6.5 foot, 70 yr old.
= Edward is a blond, 5'5", 18 year old.
= Fred is a brown-haired, 5'11", 30 year old.
Ads that can be displayed in the View as follows:
= "Miracle Grow Hair Spray" posted by Abby to be shown only to bald people.
= "NuEar Hearing Aids" posted by Betty to be shown only to people over age 65.
= "Big and Tall Shop" posted by Carol only to be shown to people over 6 feet tall.

In summary, I'm trying to filter tablular View of nodes based on attributes of the content nodes, the authors of the node, and the current user who is looking at the View.
The standard Views filter UI supports filters based on attributes of each node in the table, but does not appear to permit any use of information about the current user other than his login state.

Any advice and references to doing the filtering at the granularity of each node would be greatly appreciated!

2 Answers 2


I'll take the assumption that your using a content view, that way we're only making relationships to the user or user of said content.

Essentially you could add an entity reference to a taxonomy term which would in turn be referencing the piece of content to filter. So;

We create a new vocabulary, add the entity reference field. Create a new term, we'll call this 'bald'. Bald will make an entity reference to the content item 'Miracle Grow Hair Spray'.

Next we'll add a taxonomy reference field to the user profile. This will reference the users 'properies' from our new vocabulary. E.G. if our user is bald we will reference this term.

Lastly on the view we should have enough data to make a bridge to the piece of content being referenced by the term associated with said user.

Although basic & very roughly explained this should hopefully help.

  • Thanks. From a UX perspective, not clear how this approach works. Using the example, the Create Ad form needs to allow its author to specify that the Ad should only be shown if the current user meets a particular criterion. So when Abby creates the "Miracle Grow Hair Grow Spray" Ad node, she needs to specify its only be shown if the Current User is bald. Not clear to me how I'd do this if the taxonomic approach, requires him to add the node to the term. I'd envisioned a set of checkboxes and fill-ins on such a create form that define the display rules. May 31, 2013 at 12:52

This is really old, but in case anyone finds this I'll post it anyway.

You're essentially talking about personalization here. The approach you should take is to clearly define metadata to 'tag' (eg. taxonomy) your content as best as possible. Then, you'll need some way to join your content to your users. You don't necessarily need to abstract this more with add'l rules/logic - if possible you should instead try to share the taxonomy between the two, which makes it easier to query back later. Instead maybe try to think about it like this:

  • I'm going to create an ad called 'Miracle Hair Grow' for bald people. I will add related tags (eg. taxonomy) of 'bald' and 'male' to my ad.
  • User X is a bald male, so I'm going add the same tags to that user - I will tag them as 'bald' and 'male' (via a custom user field with entity reference to same taxonomy as above).
  • Then I will build a view that will use current user as 'context' (via relationship/contextual filter). It looks like core doesn't support this in 'content' views, but in theory its pretty straightforward: show me content filtered by the current users' 'tags'. Eg. 'Show me any content tagged as 'bald' or 'male' for User X". A straightforward way to accomplish this would maybe be with views hooks. This can get pretty complicated to figure out some of the nuances, but I would start there and see if this approach would be enough. You can see how adding more variables (eg. age, hair color, etc) will become more complicated.

Is using a view definitely a requirement? Personally if I had to do this I would think it could be a lot simpler with a custom controller using view modes. You could simply get the current user, get the terms, and even pass it to a view programmatically that takes the tid's (eg 'bald', 'male') as contextual filters. You may lose out on some of the benefits of views of course and may have to handle things like ajax on your own if needed - which may not be the end of the world. Ultimately this approach would give you the most freedom and flexibility, at the cost of code maintenance.

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.