4

I need to create a template for a view i've created (which I know how to do) but I don't want the page to be wrapped in the drupal html.php code. I want the resulting page to be only what is in the template file I create.

How do I do this? I looked online for examples but coudn't find anything.

Thanks C

EDIT:

I found this which does what I need for content types lab

function yourthemename_preprocess_html(&$vars) {
  if ($node = menu_get_object()) {
    if($node->type == "lab") {
      $vars['theme_hook_suggestions'][] = 'html__lab';
    }
  }
}

Then created a file called: html--lab.tpl.php

Can this method be used for me view? does it have to be if($node->type == "lab")? can I use something like if($view == "viewname")

Thanks

3 Answers 3

3

If you want views template not to be wrapped in html.tpl.php, page.tpl.php and any other template whatsoever, I would susggest to do the following:

function YOUR_MODULE_menu(){
    $items = array();
    $items['path/you/want/your/view/to/be/available/at'] = array(
        'type' => MENU_NORMAL_ITEM,
        'title' => 'View without wrapping templates',
        'page callback' => 'your_function_name',
        'access callback' => TRUE,
    );
    return $items;
}

function your_function_name() {
    print views_embed_view('your_view_name', 'your_display_name');
    exit;
}
5
  • Thanks Alex. Sorry to ask what may seem obvious but how/where do I use this? Commented May 1, 2012 at 6:01
  • you need to create a your own module and put this code to your_module_name.module file. In the code you also should replace YOUR_MODULE with the name of your module. You might find this piece of documentation on module creation useful: drupal.org/node/416986 Commented May 1, 2012 at 6:03
  • Thanks so much. I'll check that out. Just so i'm clear.. is this the only way to do what I need? Commented May 1, 2012 at 6:09
  • I am sure it is not the only way to do this. You might also want to try what Mohammad suggested. Both approaches require approximately the same level of efforts, so it is just a matter of taste. Commented May 1, 2012 at 6:15
  • Hi @Alex, can you please see my edit above. I would ike to know your thoughts. Commented May 2, 2012 at 13:51
1

you should create sub-theme and override html.tpl.php and page.tpl.php as your desire

then using themekey module to set your sub-them for pages which need it

0

Got the answer elsewhere... posting it here.

Added the follwoing to my template.php file:

function yourthemename_preprocess_html(&$vars) {
  if (arg(0) == 'mypage') {        
    $vars['theme_hook_suggestions'][] = 'html__mypage';        
  }
}
function yourthemename_preprocess_page(&$vars) {
  if (arg(0) == 'mypage') {        
    $vars['theme_hook_suggestions'][] = 'page__mypage';        
  }
}

Then created the following files:

html--mypage.tpl.php

page--mypage.tpl.php

Works perfectly and simple to do.

Thanks goes to @Ionut.A and @Clive

Cheers C

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.