Custom modules in Drupal 6x

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
Anonymous's picture

Hi guys.

I've been trying the forums at drupal.org and have been hanging around the IRC till someone finally suggested I should try here.

My background is 4 years of website development on the .NET platform using CMS. The framework of the CMS is based on MOSS 2007 framework.

So I'm used to defining the main layout structure in the Masterfile (page.tpl.php in Drupal) and the content placeholders (regions in drupal).

So this consept is pretty similar to Drupal. I have made a page.tpl.php file and defined the different regions (Top, main and right).
Within these regions I output the different blocks ($content, $right, $whatever etc.).

I've also made a block module and can display information using Admin -> Site building -> Blocks

So this is where I stand.

I need to make a module which uses the entire content area (main + right).
This module outputs a DVD category list (Action, Drama, Animation etc) .
Clicking a category will display the DVD's on the right side of the screen.

The datasource for the DVD list, is an existing MySQL database.
Because of this, I can't use the CCK and Views.
After some reading, I think I might be able to use Views 2 ?

Anyway, the main problem is this:

  1. How do I make a module that does not use blocks? (Node module?)
  2. I will display the contents from the module in dvdlist.tpl.php. How do I make the connection between the .module and the .tpl.php?

This tutorial is great for block nodes http://drupal.org/node/206753.
And someone suggested that I should look at this one for my current task http://drupal.org/node/231019.
But I'm not sure if the latter is what I want.

Can anyone point me in the right direction please?
Any help is appreciated.

Comments

A good resource

Itangalo's picture

Hi
I think what you want to do shouldn't be that difficult to achieve, but I get a bit confused over your terminology. I guess it comes from the word "module", which in some other frameworks mean "type of content", but in Drupal means "plugin".

Anyway - here are a few answers/comments:
* When a content type (!= module) is created, it can be used in main content are or any other region - but that's decided by how the node content is pulled out. The content is merely made available for different functions in Drupal - such as menus, lists of full nodes, and blocks.
* A module, on the other hand, has functions that decides how information will be displayed. (And some modules merely process information without displaying it.) Side content is usually made available through a block, which can be activated by an administrator and placed in any region (including the main one). "Main" content is usually made available by calling a specific path, relating to the module.
* A file called whatever.tpl.php is usually used by content types with the name "whatever". Creating a content type (with or without CCK) with the name dvdlist should automatically connect it to the template file.

I'm no developer and haven't written any modules myself, but I guess a quick-n-dirty solution to your problem would be the following:
(1) Create a content type named dvdlist, and then use php in the body field to pull out whatever mySQL information you want. (You'll need to select the proper input filter to make php work.)
(2) Add another field, "DVD titles" (using CCK), and again use PHP to pull out the information you want. However, turn off the display of this field, to make it not show in the main content area when the node is displayed.
(3) Instead, you create a Views block showing the DVD titles field only. In block administration, you make this block visible only for certain paths - the ones with the DVD list.

However, the solution above makes little use of Drupal's own functionality, and I'm sure it could be done in a much better way. (Depending on how often your source database changes, you could import a static categories list and then use the Drupal path to pull arguments to query your mySQL database. Or write a complete module to interact with the database with drop-down menus or other things.)

Anyway: I recommend the book Pro Drupal Development if you're interested in learning more about how Drupal works and how to write modules. Considering your background I think it would be perfect - you don't need all details in programming, you just need to see the "Drupal way" of doing it.

Good luck!
//Johan Falk, Sweden

Aha! I think I now

Anonymous's picture

Aha!

I think I now understood the usage of content types. It's pretty similar to EPiServer CMS.
There I can relate whatever.tpl.php to the content type "whatever".

Then I can add different fields in the content trype (where I can input data) and retrieve the values from my template.
(if you understand what I mean).

Putting PHP code in a node (as in creating a new article), is not an option.
That would be like svearing in church :)
The php code must be in the whatever.tpl.php

Books and other sources never have the eexamples I need :op
I'm lousy to figure out how things are done unless the example is very similar to what I need.

My question is:
How can I relate whatever.tpl.php to the menu item 'A' ?