Is there any way to get a list of some of many content types?

I am not asking to list nodes of content type(s).

  • by hack node template, I obviously mean for child theme. – innocent rock Aug 4 '16 at 6:07
  • Do you want to programmatically get content types shown in /admin/structure/types? – user4035 Aug 4 '16 at 9:44
  • yes, more likely /node/add. however I temporary styled the node template but I would like to render it inside a block. – innocent rock Aug 4 '16 at 9:50

List of content types

In code you can have the list of all node content types, using the node_type_get_names() method :

foreach (node_type_get_names() as $name => $type) {
     // Do something

After, you'll have to sort them if you do not want to use them all.

Template override

It is not a good practice to hack any files of the Drupal installation.

But you can easily override any template files provided by the core or a module, directly in your theme folder.

Have a look at this subject : Drupal 7 Template (Theme Hook) Suggestions.

To have a custom content type template, just take the default "node.tpl.php" file, and copy it in your template theme folder, with a name like "node--[type-machine-name].tpl.php" (you'll have to replace the "_" in the type_name by "-").

Custom node add form

And finally I already saw some website using a override node form page using page manager module. But I cannot say how they've done 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.