2012-03-25 102 views
2

我想在drupal中呈現「基本頁面」的內容。事情是這樣的問題:displaying a Drupal view without a page template around it但爲Drupal 7在Drupal 7中顯示沒有模板的drupal頁面

我幾乎嘗試工作:

function mytheme_preprocess_page(&$variables, $hook) { 
    if (isset($_GET['ajax']) && $_GET['ajax'] == 1) { 
     $variables['theme_hook_suggestions'][] = 'page__ajax'; 
    } 
} 

而且具有在同一目錄中名爲page--ajax.tpl.php文件,其中的template.php住:

<?php print $page['content']; ?> 

問題是它仍然從側欄呈現菜單和我的兩個自定義塊。我只想要頁面內容。我應該改變什麼?

回答

6

你快到了。唯一需要的是添加一個自定義HTML包裝器模板。

  • 添加功能template.php
function THEMENAME_preprocess_html(&$variables, $hook) { 
    if (isset($_GET['ajax']) && $_GET['ajax'] == 1) { 
    $variables['theme_hook_suggestions'][] = 'html__ajax'; 
    } 
} 
  • 創建一個名爲html--ajax.tpl.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" 
    "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">` 

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 
    <?php print $styles; ?> 
    <?php print $scripts; ?> 
</head> 
<body class="<?php print $classes; ?>"> 
    <?php print $page_top; ?> 
    <?php print $page; ?> 
    <?php print $page_bottom; ?> 
</body> 
</html> 
  • 刷新所有緩存文件。就這樣。
+0

該列表項混淆瞭解析器。我從你的鏈接中輸入了代碼,因爲對於未來的人來說沒有什麼比發現正確的解決方案在這個死鏈接上更糟了:)。我會很快嘗試你的建議並回復你。 – 2012-03-26 15:24:46

+0

請同時嘗試<?php print $ page; ?>沒有別的(因爲這是該文件的第一個版本;)。謝謝。 – 2012-03-26 15:29:03

+0

不幸的是,這並沒有奏效。我得到完全相同的輸出。我驗證了使用'html - ajax'和'page - ajax'模板(通過打印HTML註釋)。我認爲這個問題是塊看起來是頁面中的$ page ['content']' - ajax的一部分,所以它們無論如何都得到了渲染。 – 2012-03-26 17:43:02

3

基於Ufonion實驗室的答案,我能夠完全去除 圍繞在Drupal 7頁內容中的所有HTML輸出由 實現既hook_preprocess_pagehook_preprocess_html在 我的主題的template.php,這樣:

function MY_THEME_preprocess_page(&$variables) { 
    if (isset($_GET['response_type']) && $_GET['response_type'] == 'embed') { 
    $variables['theme_hook_suggestions'][] = 'page__embed'; 
    } 
} 

function MY_THEME_preprocess_html(&$variables) { 
    if (isset($_GET['response_type']) && $_GET['response_type'] == 'embed') { 
    $variables['theme_hook_suggestions'][] = 'html__embed'; 
    } 
} 

然後我添加了兩個模板,我的主題:html--embed.tpl.php

<?php print $page; ?> 

page--embed.tpl.php

<?php print render($page['content']); ?> 

現在,當我打開一個節點頁面,如http://example.com/node/3,我看到 完整的網頁一切正常,但是當我添加了RESPONSE_TYPE 參數,如http://example.com/node/3?response_type=embed,我 只有獲取頁面內容的<div>,以便它可以嵌入到另一個頁面中。

無恥地從這裏採取形式: displaying a Drupal view without a page template around it(第二個最佳答案drupal 7)。

阿列克謝解決方案仍然使用頁面模板負責顯示塊