0

I am trying to allow the user to set a custom image to display in the header on node pages that have a header_image field and to display a default header image on all other pages (including system and module generated pages).

I thought I could do this by creating a "Header Image" view and using a contextual filter to get the header_image field on the displayed node. This works okay when displaying a node that has the header_image field but not on a page that doesn't have that field. Because this view is a block the contextual filter uses the default value of "Content ID from URL" and I can't use a fixed default value.

I am guessing I have to use the preprocess_page function and field_has_data or perhaps the Entity API Module to check if the node has data in the header_image field. If there is no header_image field or it has no value I would like to use the default image for that field. Is there anyway to specify using the default image that was set by the user? other wise I would use the default image at file_stream_wrapper_get_instance_by_uri('public://')->getDirectoryPath().'/default_images/default_header.jpg'

There must be a common solution to this problem.. Actually I just had a thought.. what if there are multiple nodes on a page? Any suggestions what I should do to accomplish this?

1 Answer 1

0

I recently tried to do this but stumbled then over the Header Image Module which does this perfectly. It allows you to create a block which holds any content (for example a custom content type) and ads it to a block. You can specify on each content where it should be displayed (nid, path, term etc.).

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.