开发者

Best practices to implement custom functionality on website

I was wondering if someone with Drupal experience could advice what are the best practices in the following situations. I think they are all common tasks for any website that you build.

  1. Display a custom HTML of a certain content type at front-page (e.g., only the link and title).

    Should I build a module only for this?

  2. Customize the login form HMTL, including inputs, labels etc, to something very different from the default l开发者_运维技巧ogin block. Again, another module?

  3. Format the node view of some content types; for example: showing additional fields values. I have some Joomla experience and with it, it's very easy to override the template on your theme.

But with Drupal, it seems HTML is hard-coded on PHP files and there are very few thing that uses templates. Or am I missing something?


  1. You should create a view (from Views module), and for this create display 'block'. This block you can use later on your site. Within your view settings you can choose what and how you will display.

  2. It depends what you would like to put there. If you put just some static text, change theme could be a solution. But still, a bit smelly. What you should do, is to create a module use hook_form_FORM_ID_alter and add both - field to your form, and code to use values which user added.

  3. Change templates for this content type in your custom theme; or use Panels module - here you have nice introduction; or use Display Suite module - which do pretty much the some work as creating a template


html is in php files, but where else can it go? Drupal also has it template overwrite system. The customization of the theme can be usually done using that alone.

As for your questions (there are also other alternative)

  1. load the content type in view/block, display in list format on home page.

  2. create your own theme for css changes. create custom tpl.php for layout, and div naming etc.

  3. same as above.

It doesn't hurt to create a new module, but generally it's not necessary unless you are going for something like a muti-step form.


You can use both Views & Panels in order to achieve what you've mentioned above.

For instance, Panels gives you the option to override the home page with your own content. This content can be organized with Views.

From drupal.org:

"The Views module provides a flexible method for Drupal site designers to control how lists and tables of content (nodes in Views 1, almost anything in Views 2) are presented."

"The Panels module allows a site administrator to create customized layouts for multiple uses. At its core it is a drag and drop content manager that lets you visually design a layout and place content within that layout."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜