3

I have created a content type which has some fields, and I want these fields to be displayed as a block.

I've tried renaming a block in my 'theme/template' as block--[machine-name].tpl.php but is of no use.

4

So, if I understand this correctly, your asking how you can make a block which displays fields from a content type based on some logical requirements, then provide an .tpl override so you can do some custom work to the output of those fields? I hope thats right.

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

  • Step 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.
  • Step 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
  • Step 3: Set up your block view appropriately. See screenshot for more specific details for this: https://skitch.com/therealwebguy/8ksw9/block-step-2
  • Step 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:

  • We've create a content type and added fields to it.
  • We've added actual nodes of the new content type for testing.
  • 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.
  • 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.

Good Luck!

  • best answer. But the screenshot link is not working. Can you add the content in any different way so we can check into it? – Rick Dec 1 '19 at 12:22
1

I'd suggest one of the following modules:

Node Blocks:

This module allows you to specify content type(s) as being a block. This allows the content managers of the site to edit the block text and title without having to access the block administration page. Users only need edit access to that node in order to edit it.

It is very handy to create a simple block content type and enable this content type for blocks and use these in place of the normal 'add block' functionality.

Nodes In Block:

Nodes in block makes it possible to add nodes into a block. A number of configurable blocks are generated which you can assign to a region. Visibility settings of this block are automatically set to 'Show on only the listed pages'. On the node content form, you define the weight and visibility per node thus making it easier for content administration as all your content is now in the same place. With this module, you don't have to explain your customers how blocks work but is still able to decide on which pages content must be rendered.

Simply renaming a block template with the name of your custom content type won't generate a block from it.

0

Use the Bean module. It creates blocks as entities so you can add fields to them. Here is an excerpt about it from the module's project page:

Think of a Bean as a method to provide new types (compared to node this would be a content type) which then provides an add content interface to create as many blocks as you require. The bean content can then be placed around the site just like any other block.

Your Answer

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