开发者

Drupal: Content Type templates

It is possible to choose different templates when I am creating a开发者_开发问答 new node?

For example: When i want to create a node of Content Type Product, i want to choose between 4 different templates.


I have two answers:

1) create a CCK field that the user will choose what template to use, (e.g. field_template), and add this snippet in your template.php:

function mytheme_preprocess_node(&$vars) {
  if (!empty($vars['field_template'][0]['value'])) {
    array_unshift($vars['template_files'], 'node-' . $vars['field_template'][0]['value']);
  }
}

That will then try to use node-template.tpl.php as your template file, and will fallback to node.tpl.php if it doesn't find it.

2) create a Taxonomy for this content type, and design by the taxonomy (something like the code above, only a little modified).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜