3

I am using the ThemeKey module to change the theme for mobile users. I have a custom View Mode called Mobile to display different content. I would like to have when my mobile theme is loaded for the node to use the Mobile View Mode that I created instead of the Default View Mode.

I would like to do this in the theme. Either hooking into the theme with a module or just placing the php in a template override.

Thanks!


Ok I found a few items that get my closer to what I am needing. I just can't seem to get it to work. I am testing this idea with the teaser for now.

<?php
$rendered_teaser = render(node_view(node_load($nid), 'teaser'));
?>

By using the node number I am able to get it to print in the page.tpl.php file fine. But I am wanting to get the node I am on and convert the view mode from full to teaser.

<?php
$rendered_teaser = render(node_view(node_load(2), 'teaser'));
?>

I found that information be reading the links below. I am still not able to get it to work but close. For some reason I get errors. I think it has to do with me placing it in the node.tpl.php and the page.tpl.php template file.

http://drupal.org/node/985022 http://drupal.stackexchange.com/questions/36028/getting-the-auto-summary-from-a-node-bodyhttp://drupal.stackexchange.com/questions/23961/print-result-of-a-node-load


And I got it working. Any comments appreciated. I placed this on the top of the page.tpl.php.

<?php 
$nid = $node->nid;
if ($nid) {
 $nid = $node->nid;
 $rendered_view = node_view(node_load($nid), 'teaser');
} 
?>

And I placed the print rendered_teaser where I wanted the node view to be printed.

<?php 
if ($nid) {
 print render($rendered_view);
} 
 else {
  print render($page['content']);
 }
?>
2
  • If I use a node number (2) instead of $nid it works perfectly in the page.tpl.php. Commented Sep 5, 2012 at 15:48
  • By using $nid = $node->nid; I am able to get the current node ID. Commented Sep 5, 2012 at 16:03

1 Answer 1

1

Since your mobile theme is a different theme a viable alternative is to just use the same display modes everywhere and then theme that display mode differently by overriding the node.tpl.php file differently in each theme.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.