Search code examples
drupaldrupal-7drupal-blocks

How to add custom fields to blocks in Drupal 7?


I'd like to be able to add custom fields to blocks in Drupal? I have a header area that spans the entire width of the page. Below that will be a left column for body content and right sidebar for various blocks. The header area needs to have a background image with text displayed on top of it. Was hoping to do this through blocks with custom fields for the background image and text.


Solution

  • You could achieve this using the Views module, Fields and blocks.

    1. Create a content type called Background Image with an Image Upload field and any other fields you'd like to display
    2. Using Views create a View that displays as a block. You can set up the fields to rewrite however you'd like.
    3. Using your Views settings, display your background image as a path rather than an image.

    For instance you could set up something like this using field replacements in views:

    <div style="background: [field_image] left top no-repeat">
    <h2>[title]</h2>
    <p>[field_whatever]</p>
    </div>
    

    It seems like a bit of overkill, but it would get it in the hands of the client. You'd also want to do something restrictions to keep it only using a certain node ID so that they don't create a million background image nodes and wreck the site. Hope this helps.