I want to use render function but I don't want to show all the data which is there in the particular field. So how can restrict something from rendering in template file. Scenario is:

I have reference one field to another contentype, and I am rendering field in template file. But problem is even though the referenced node is not published, that data is displaying in the rendered field. So how can I restrict like if node is published then only I want to display that data.

One more concern is if it is possible with inbuilt functions only that will be great that saves my time of writing code and designing the data.

  • You can control the output with conditions in preprocess functions. – Jimmy Ko Oct 7 '16 at 11:38
  • can u please elaborate with a code,so that it will be great. – Suraj Oct 7 '16 at 11:43
  • I would like to but it takes time. I will do that when I got enough spare time today later. :) – Jimmy Ko Oct 7 '16 at 11:48
  • Are you viewing the rendered content while logged out? I don't believe Drupal permissions will allow unpublished content to be viewed by non-users by default -- even if accessed through an entity reference field. – Ryan Oct 8 '16 at 21:34

You should be putting the business logic of deciding what you want to show (or hide) in a preprocess function in your template.php and make use of the show and hide functions to specify what you want rendered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.