Drupal 7: Is it possible to print a cck field in the html.tpl file?
I a开发者_运维技巧m looking to use a cck field as the page title. The $pagetitle variable is found in the html.tpl.php file. But it does not look as if I can access any nodes.
Is there a way to do this?
If you would like a module to do this, check out the Page Title module.
This module gives you granular control over the page title. You can specify patterns for how the title should be structured and, on content creation pages, specify the page title separately to the content's title.
I think there may be a bug with getting the CCK fields as available tokens but I believe there's a patch available for it.
You can identify the relevant cck field and print its value instead of the default page title. Try:
drupal_set_message('<pre>' . print_r($node, TRUE) . '</pre>');
... in your content type template file. This will output all the contents of $node. Beware, it will be messy, and it may take you a while to find what you're looking for!
Out of curiosity, why are doing this?
You can do this by using hook_preprocess_page() function and change the page title. See http://api.drupal.org/api/drupal/modules--system--theme.api.php/function/hook_preprocess_HOOK/7#comment-24423
精彩评论