I tried to create a block called contact details. I already created a content type called contact. I wanted to add the content of each contact content type in my custom block. I researched a lo abd I'm confused.


In block_view of your custom block write this code

$nids = db_select('node', 'n')
    ->fields('n', array('nid'))
    ->fields('n', array('type'))
    ->condition('n.type', 'contact')
$nodes = node_load_multiple($nids);

Loop $nodes with foreach and get the fields whatever you want.

  1. Install and enable the Views module.
  2. Create a view with 'Block' display.
  3. Filter by content type 'contact'. You can also choose sort options, etc.
  4. Go to the Blocks administration page at Administration > Structure > Blocks.
  5. Enable the Views block.

So you can do some custom work to the output of those fields? I hope that's right.

So this is relatively easy depending in how you want to go about this.

Follow steps:

  1. You've created your content type and added all of the fields that you want. I'm assuming you've also created some content already to test the next part.

  2. You need to create a view that has a block display. See screenshot for an example. https://skitch.com/therealwebguy/8ksue/block-step-1

  3. Set up your block view appropriately. See screenshot for more specific details for this: https://skitch.com/therealwebguy/8ksw9/block-step-2

  4. If you refer to the screenshot provided in Step 3, you'll notice in the bottom right that I have highlighted the "Information" link for the Theme layer. Clicking this link will bring up a list of all of the .tpl files you can create for this view to target what you need. It has everything from the top-level view tpl to the output of a single field being rendered by the view. Choose the one that's best for you needs, copy the HTML provided and add it the view.tpl.php file you've chosen to use.

Lets recap:

  1. We've create a content type and added fields to it.
  2. We've added actual nodes of the new content type for testing.
  3. We've created a new view which will provide a block display, showing us > the field values of our content type that we want to show.
  4. We've created a custom tpl override for the view of our choice to do some more customization at the theme level that best fits our needs.

The only thing left to do is to head over to your blocks administration and put the block where you want it.

Hope this help to solve your problem/doubt.

  • Nice tutorial, but this isn't a tutorial site. #3 in your recap is really the only step relevant to the question, and that's already been covered. – othermachines Aug 14 '15 at 14:08

Your need to use core contact form and uses contact save to save and fetch contact detail. thats it.

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.