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.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI 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.
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.
Lets recap:
The only thing left to do is to head over to your blocks administration and put the block where you want it.
Good Luck!
I'd suggest one of the following modules:
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 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.
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.