Drupal: How to theme a module

2019-05-28 01:33发布

问题:

I'm trying to theme a modules output. In particular i'm working on http://drupal.org/project/service_links

Any idea how that works?

Thanks in advance!

回答1:

Generally, if you want to theme a module you have a few options.

  1. Overwrite theme functions. You can overwrite the theme functions that the module uses/implements to change the markup, one example of such a function is theme_service_links_node_format. You change make a function in your theme's template.php called 'your_theme_name_service_links_node_format' and make your custom markup in it instead.

  2. CSS. If you don't need to change the actual markup of a modules output, you only need to add the needed css, to theme it into your liking.

  3. In some cases, it doesn't look like sercive links is such a case, you can also make your own templates, and make Drupal use them instead.

  4. Another way, again it doesn't look like service is service links is such a case, is to implement preprocess functions in your template.php. This is needed if you want to alter how certain template variables are generated.



回答2:

If you want to implement your own theming function services links defines 3 themables. In your theme you should imlement the following

  • yourtheme_service_links_build_link()
  • yourtheme_service_links_node_format()
  • yourtheme_service_links_node_format()

    'service_links_build_link' => array(
      'arguments' => array(
        'text' => NULL,
        'url' => NULL,
        'title' => NULL,
        'image' => NULL,
        'nodelink' => NULL,
      ),
    ),
    'service_links_node_format' => array(
      'arguments' => array('links' => NULL),
    ),
    'service_links_block_format' => array(
      'arguments' => array('items' => NULL),
    ),
    

Have a look at http://drupalcode.org/viewvc/drupal/contributions/modules/service_links/service_links.module?view=markup line 389 and below



回答3:

What's the problem? I mean, every module should use a different name for main container and so. You can use css selector in clever way to refer the template pages.

For example, the FAQ module use identificator to all part of html output, like faq-question and faq-answer in the main page.

Just inspect your resulting code and css it, if possible modify the module-related css!



回答4:

If the module implements its own theme hooks you can use that. You can also use CSS.



标签: drupal