0

I need to render a limited number of fields from a given content type, without exposing the new ones I may add some day in the future.

Now I have:

print render($page)

When a new field is added to the content type, I have that added to the render($page) as well. I don't want this to happen. Aside hiding the field from "admin/structure/types/manage/CONTENT_TYPE/display", how can I programmatically exclude new fields from render.

2 Answers 2

0

A common way is to use hide() function in a preprocess hook as:

hide($page['field_machine_name']);
1
  • I don't know the field name I will add tomorrow
    – Augusto
    Commented Mar 14, 2018 at 14:08
0

What you could do is not render out all of $page. So you could get rid of:

print render($page)

And instead just render the elements within it you want e.g. :

print render($page['field_my_field']);

That will mean no matter what other fields you add in the future only the ones you specifically render in your template will be shown

1
  • This would imply a parcial CSS rewrite, already tested.
    – Augusto
    Commented Mar 14, 2018 at 20:35

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.