显示一个没有页面模板的Drupal视图

时间:2022-09-12 08:43:58

I would like to display a Drupal view without the page template that normally surrounds it - I want just the plain HTML content of the view's nodes.

我想显示一个没有通常围绕它的页面模板的Drupal视图 - 我只想要视图节点的纯HTML内容。

This view would be included in another, non-Drupal site.

此视图将包含在另一个非Drupal站点中。

I expect to have to do this with a number of views, so a solution that lets me set these up rapidly and easily would be the best - I'd prefer not to have to create a .tpl.php file every time I need to include a view somewhere.

我希望必须通过一些视图执行此操作,因此我可以快速轻松地设置这些视图的解决方案是最好的 - 我不希望每次需要时都创建.tpl.php文件在某处包含一个视图。

15 个解决方案

#1


49  

I was looking for a way to pull node data via ajax and came up with the following solution for Drupal 6. After implementing the changes below, if you add ajax=1 in the URL (e.g. mysite.com/node/1?ajax=1), you'll get just the content and no page layout.

我正在寻找一种通过ajax提取节点数据的方法,并为Drupal 6提出了以下解决方案。在实现下面的更改后,如果在URL中添加ajax = 1(例如mysite.com/node/1?ajax= 1),你只会得到内容,没有页面布局。

in the template.php file for your theme:

在主题的template.php文件中:

function phptemplate_preprocess_page(&$vars) {

  if ( isset($_GET['ajax']) && $_GET['ajax'] == 1 ) {
        $vars['template_file'] = 'page-ajax';
  }

}

then create page-ajax.tpl.php in your theme directory with this content:

然后使用以下内容在主题目录中创建page-ajax.tpl.php:

<?php print $content; ?>

#2


19  

Based on the answer of Ufonion Labs I was able to completely remove all the HTML output around the page content in Drupal 7 by implementing both hook_preprocess_page and hook_preprocess_html in my themes template.php, like this:

基于Ufonion Labs的答案,我能够通过在我的主题template.php中实现hook_preprocess_page和hook_preprocess_html来完全删除Drupal 7中页面内容周围的所有HTML输出,如下所示:

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';
  }
}

Then I added two templates to my theme: html--embed.tpl.php:

然后我为我的主题添加了两个模板:html - embed.tpl.php:

<?php print $page; ?>

and page--embed.tpl.php:

和页面 - embed.tpl.php:

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

Now when I open a node page, such as http://example.com/node/3, I see the complete page as usual, but when I add the response_type parameter, such as http://example.com/node/3?response_type=embed, I only get the <div> with the page contents so it can be embedded in another page.

现在,当我打开一个节点页面(例如http://example.com/node/3)时,我会照常看到整个页面,但是当我添加response_type参数时,例如http://example.com/node/ 3?response_type = embed,我只获得带有页面内容的

,因此它可以嵌入到另一个页面中。

#3


7  

I know this question has already been answered, but I wanted to add my own solution which uses elements of Philadelphia Web Design's (PWD) answer and uses hook_theme_registry_alter, as suggested by Owen. Using this solution, you can load the template directly from a custom module.

我知道这个问题已经得到解答,但我想添加自己的解决方案,它使用费城网页设计(PWD)答案的元素,并使用了欧文建议的hook_theme_registry_alter。使用此解决方案,您可以直接从自定义模块加载模板。

First, I added raw.tpl.php to a newly created 'templates' folder inside my module. The contents of raw.tpl.php are identical to PWD's page-ajax.tpl.php:

首先,我将raw.tpl.php添加到模块中新创建的“templates”文件夹中。 raw.tpl.php的内容与PWD的page-ajax.tpl.php完全相同:

<?php print $content; ?>

Next, I implemented hook_preprocess_page in my module in the same fashion as PWD (except that I modified the $_GET parameter and updated the template file reference:

接下来,我以与PWD相同的方式在我的模块中实现了hook_preprocess_page(除了我修改了$ _GET参数并更新了模板文件引用:

function MY_MODULE_NAME_preprocess_page(&$vars) {
    if ( isset($_GET['raw']) && $_GET['raw'] == 1 ) {
        $vars['template_file'] = 'raw';
    }
} 

Finally, I implemented hook_theme_registry_alter to add my module's 'templates' directory to the theme registry (based on http://drupal.org/node/1105922#comment-4265700):

最后,我实现了hook_theme_registry_alter,将我模块的'templates'目录添加到主题注册表中(基于http://drupal.org/node/1105922#comment-4265700):

function MY_MODULE_NAME_theme_registry_alter(&$theme_registry) {
   $modulepath = drupal_get_path('module','MY_MODULE_NAME');
   array_unshift($theme_registry['page']['theme paths'], $modulepath.'/templates');
}

Now, when I add ?raw=1 to the view's URL path, it will use the specified template inside my module.

现在,当我向视图的URL路径添加?raw = 1时,它将使用我的模块中的指定模板。

#4


5  

For others who may hit this page, if you're just working with standard callbacks (not necessarily views), this is easy. In your callback function, instead of returning the code to render within the page, use the 'print' function.

对于可能会访问此页面的其他人,如果您只是使用标准回调(不一定是视图),这很容易。在回调函数中,使用'print'函数,而不是返回要在页面内呈现的代码。

For example:

例如:

function mymodule_do_ajax($node)
{
    $rval = <<<RVAL
        <table>
            <th>
                <td>Data</td>
                <td>Data</td>
                <td>Data</td>
            </th>
            <tr>
                <td>Cool</td>
                <td>Cool</td>
                <td>Cool</td>
            </tr>
        </table>
RVAL;

    //return $rval; Nope!  Will render via the templating engine.
    print $rval; //Much better.  No wrapper.
}

Cheers!

干杯!

#5


3  

Another way to do it which I find very handy is to add a menu item with a page callback function that doesn't return a string:

我觉得非常方便的另一种方法是添加一个菜单项,其中包含一个不返回字符串的页面回调函数:

Example:

例:

/**
 * Implementation of hook_menu.
 */
function test_menu(){
  $items['test'] = array (
    /* [...] */ 
    'page callback' => 'test_callback',
    /* [...] */ 
  );
  return $items;
}

function test_callback() {
  // echo or print whatever you want
  // embed views if you want
  // DO NOT RETURN A STRING
  return TRUE;
}    

-- Update

- 更新

It would be much better to use exit(); instead of return TRUE; (see comment).

使用exit()会好得多;而不是返回TRUE; (见评论)。

#6


2  

Hey, here's yet another way of doing it:

嘿,这是另一种方式:

1) Download and install Views Bonus Pack (http://drupal.org/project/views_bonus) 2) Create a Views display "Feed" and use style "XML" (or something you think fits your needs better). 3) If you're not satisfied with the standard XML output, you can change it by adjusting the template for the view. Check the "theme" settings to get suggestions for alternative template names for this specific view (so you'll still have the default XML output left for future use).

1)下载并安装Views Bonus Pack(http://drupal.org/project/views_bonus)2)创建一个视图显示“Feed”并使用样式“XML”(或者你认为更适合你需要的东西)。 3)如果您对标准XML输出不满意,可以通过调整视图模板来更改它。检查“主题”设置以获取此特定视图的替代模板名称的建议(因此您仍将保留默认的XML输出以供将来使用)。

Good luck! //Johan Falk, NodeOne, Sweden

祝你好运! //瑞典NodeOne的Johan Falk

#7


2  

Based on answer of Philadelphia Web Design (thanks) and some googling (http://drupal.org/node/957250) here is what worked for me in Drupal 7 to get chosen pages displayed without the template:

根据费城网页设计的答案(谢谢)和一些谷歌搜索(http://drupal.org/node/957250),这是在Drupal 7中为我提供的,以便在没有模板的情况下显示所选页面:

function pixture_reloaded_preprocess_page(&$vars)
{
  if ( isset($_GET['vlozeno']) && $_GET['vlozeno'] == 1 ) {
        $vars['theme_hook_suggestions'][] = 'page__vlozeno';
  }   
}

instead of phptemplate, in D7 there has to be the name_of_your_theme in the name of the function. Also, I had to put two underscores __ in the php variable with the file name, but the actual template file name needs two dashes --

而不是phptemplate,在D7中必须有函数名称中的name_of_your_theme。另外,我不得不在php变量中添加两个带有文件名的下划线__,但实际的模板文件名需要两个破折号 -

content of page--vlozeno.tpl.php :

页面内容 - vlozeno.tpl.php:

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

The output, however, still has got a lot of wrapping and theme's CSS references. Not sure how to output totally unthemed data...

但是,输出仍然有很多包装和主题的CSS引用。不确定如何输出完全未经训练的数据......

#8


2  

Assuming you're in Drupal 6, the easiest way to do this is to put a phptemplate_views_view_unformatted_VIEWNAME call in template.php (assumes your view is unformatted - if it's something else, a list say, use the appropriate theme function). Theme the view results in this theme call then, instead of returning the results as you normally would, print them and return NULL. This will output the HTML directly.

假设您在Drupal 6中,最简单的方法是在template.php中放置一个phptemplate_views_view_unformatted_VIEWNAME调用(假设您的视图未格式化 - 如果是其他内容,则列表说,使用适当的主题函数)。然后将视图结果主题化为此主题调用,而不是像往常一样返回结果,打印它们并返回NULL。这将直接输出HTML。

PS - make sure to clear your cache (at /admin/settings/performance) to see this work.

PS - 确保清除缓存(在/ admin / settings / performance)以查看此工作。

#9


1  

there are probably a number of ways around this, however, the "easiest" may be just setting your own custom theme, and having the page.tpl.php just be empty, or some random divs

这可能有很多方法,但是,“最简单”可能只是设置自己的自定义主题,并且page.tpl.php只是空的,或者一些随机的div

// page.tpl.php
<div id="page"><?php print $content ?></div>

this method would basically just allow node.tpl.php to show (or any of drupal's form views, etc...) and would be an easy way to avoid modifying core, or having to alter the theme registry to avoid displaying page.tpl.php in the first place.

这个方法基本上只允许node.tpl.php显示(或任何drupal的表单视图等),并且是一种避免修改核心的简单方法,或者必须改变主题注册表以避免显示page.tpl .php首先。

edit: see comments

编辑:见评论

ok i played around with views a bit, it looks like it takes over and constructs it's own "node.tpl.php" (in a sense) for display within "page.tpl.php". on first glance, my gut feeling would be to hook into theme_registry_alter().

好吧,我玩了一些视图,看起来它接管并构建它自己的“node.tpl.php”(在某种意义上)在“page.tpl.php”中显示。乍一看,我的直觉就是挂钩到theme_registry_alter()。

when you're looking at a views page, you have access to piles of information here, as well as the page.tpl.php paths/files. as such i would do something like:

当您查看视图页面时,您可以访问此处的大量信息,以及page.tpl.php路径/文件。因此我会做类似的事情:

function modulejustforalteration_theme_registry_alter(&$variables) {
  if (isset($variables['views_ui_list_views']) ) {
  // not sure if that's the best index to test for "views" but i imagine it'll work
  // as well as others
    $variables['page']['template'] = 'override_page';        
  }
}

this should allow you to use a "override_page.tpl.php" template in your current theme in which you can remove anything you want (as my first answer above).

这应该允许您在当前主题中使用“override_page.tpl.php”模板,您可以在其中删除任何您想要的内容(作为我上面的第一个答案)。

a few things:

一些东西:

  • as i said, not sure if views_ui_list_views is always available to check against, but it sounds like it should be set if we're looking at a view
  • 正如我所说,不确定views_ui_list_views是否始终可用于检查,但听起来应该设置如果我们正在查看视图
  • you can alter the theme paths of the page array if you prefer (to change the location of where drupal will look for page.tpl.php, instead of renaming it altogether)
  • 如果您愿意,可以更改页面数组的主题路径(更改drupal查找page.tpl.php的位置,而不是完全重命名)
  • there doesn't appear to be any identifiers for this specific view, so this method might be an "all views will be stripped" approach. if you need to strip the page.tpl.php for a specific view only, perhaps hooking into template_preprocess_page() might be a better idea.
  • 此特定视图似乎没有任何标识符,因此此方法可能是“所有视图将被剥离”的方法。如果你只需要为特定视图剥离page.tpl.php,也许挂钩到template_preprocess_page()可能是个更好的主意。

#10


1  

I like the Drupal module. BUt, here's another way.

我喜欢Drupal模块。 BUt,这是另一种方式。

copy page.tpl.php in your theme folder to a new file called page-VIEWNAME.tpl.php, where VIEWNAME is the machine-readible name of the view.

将主题文件夹中的page.tpl.php复制到名为page-VIEWNAME.tpl.php的新文件中,其中VIEWNAME是视图的机器可读名称。

Then edit page-VIEWNAME.tpl.php to suit.

然后编辑page-VIEWNAME.tpl.php以适应。

#11


1  

There is also http://drupal.org/project/pagearray which is a general solution...

还有http://drupal.org/project/pagearray这是一个通用的解决方案......

Also, @Scott Evernden's solution is a cross site scripting (XSS) security hole. Don't do that. Read the documentation on drupal.org about how to Handle Text in a Secure Fashion http://drupal.org/node/28984

此外,@ Scott Evernden的解决方案是跨站点脚本(XSS)安全漏洞。不要那样做。阅读drupal.org上有关如何以安全时尚处理文本的文档http://drupal.org/node/28984

#12


1  

A simple way to display content of a special content-type you wish to display without all the stuff of the page.tpl.php:
Add the following snippet to your template.php file:

显示您希望显示的特殊内容类型内容的简单方法,无需使用page.tpl.php的所有内容:将以下代码段添加到template.php文件中:

function mytheme_preprocess_page(&$vars) {
  if ($vars['node'] && arg(2) != 'edit') {
      $vars['template_files'][] = 'page-nodetype-'. $vars['node']->type;
    }
}

Add a page-nodetype-examplecontenttype.tpl.php to your theme, like your page.tpl.php but without the stuff you don't want to display and with print $content in the body.

在你的主题中添加一个page-nodetype-examplecontenttype.tpl.php,就像你的page.tpl.php一样,但没有你想要显示的东西,并且在主体中有print $ content。

#13


0  

If I understand your question, you want to have nodes which contain all the HTML for a page, from DOCTYPE to </HTML>. What I would do is create a content type for those nodes -- "fullhtml" as its machine-readable name -- and then create a node template for it called node-fullhtml.tpl.php. You can't just dump the node's contents, as they've been HTML-sanitized. node.fullhtml.tpl.php would literally be just this:

如果我理解您的问题,您希望拥有包含页面所有HTML的节点,从DOCTYPE到 。我要做的是为这些节点创建一个内容类型 - “fullhtml”作为其机器可读的名称 - 然后为它创建一个名为node-fullhtml.tpl.php的节点模板。您不能只是转储节点的内容,因为它们已经过HTML清理。 node.fullhtml.tpl.php就是这样:

echo htmlspecialchars_decode($content);

Then you'll need a way to override the standard page.tpl.php. I think what you could do is at the top of your page.tpl.php check the $node's content type, and bail out if it's fullhtml. Or, set a global variable in node-fullhtml.tpl.php that page.tpl.php would check for.

然后你需要一种方法来覆盖标准的page.tpl.php。我认为你可以做的就是在你的page.tpl.php的顶部检查$ node的内容类型,如果它是fullhtml则挽救。或者,在page.tpl.php中检查的node-fullhtml.tpl.php中设置一个全局变量。

I'm no Drupal expert, but that's how I'd do it. I'm talking off the cuff, so watch for devils in the details.

我不是Drupal专家,但我就是这样做的。我正在谈论袖口,所以请注意细节中的恶魔。

#14


0  

I see you have already gone and made yourself a module, so this may no longer help, but it is fairly easy to get a view to expose an rss feed, which might be an easier way of getting at the content, especially if you want to include it on a different site.

我看到你已经离开并自己做了一个模块,所以这可能不再有用了,但是很容易获得一个暴露rss feed的视图,这可能是获取内容的一种更简单的方法,特别是如果你想要的话将其包含在其他网站上。

#15


0  

On D7 you can use menu_execute_active_handler

在D7上,您可以使用menu_execute_active_handler

$build = menu_execute_active_handler('user', FALSE);
return render($build);

#1


49  

I was looking for a way to pull node data via ajax and came up with the following solution for Drupal 6. After implementing the changes below, if you add ajax=1 in the URL (e.g. mysite.com/node/1?ajax=1), you'll get just the content and no page layout.

我正在寻找一种通过ajax提取节点数据的方法,并为Drupal 6提出了以下解决方案。在实现下面的更改后,如果在URL中添加ajax = 1(例如mysite.com/node/1?ajax= 1),你只会得到内容,没有页面布局。

in the template.php file for your theme:

在主题的template.php文件中:

function phptemplate_preprocess_page(&$vars) {

  if ( isset($_GET['ajax']) && $_GET['ajax'] == 1 ) {
        $vars['template_file'] = 'page-ajax';
  }

}

then create page-ajax.tpl.php in your theme directory with this content:

然后使用以下内容在主题目录中创建page-ajax.tpl.php:

<?php print $content; ?>

#2


19  

Based on the answer of Ufonion Labs I was able to completely remove all the HTML output around the page content in Drupal 7 by implementing both hook_preprocess_page and hook_preprocess_html in my themes template.php, like this:

基于Ufonion Labs的答案,我能够通过在我的主题template.php中实现hook_preprocess_page和hook_preprocess_html来完全删除Drupal 7中页面内容周围的所有HTML输出,如下所示:

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';
  }
}

Then I added two templates to my theme: html--embed.tpl.php:

然后我为我的主题添加了两个模板:html - embed.tpl.php:

<?php print $page; ?>

and page--embed.tpl.php:

和页面 - embed.tpl.php:

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

Now when I open a node page, such as http://example.com/node/3, I see the complete page as usual, but when I add the response_type parameter, such as http://example.com/node/3?response_type=embed, I only get the <div> with the page contents so it can be embedded in another page.

现在,当我打开一个节点页面(例如http://example.com/node/3)时,我会照常看到整个页面,但是当我添加response_type参数时,例如http://example.com/node/ 3?response_type = embed,我只获得带有页面内容的

,因此它可以嵌入到另一个页面中。

#3


7  

I know this question has already been answered, but I wanted to add my own solution which uses elements of Philadelphia Web Design's (PWD) answer and uses hook_theme_registry_alter, as suggested by Owen. Using this solution, you can load the template directly from a custom module.

我知道这个问题已经得到解答,但我想添加自己的解决方案,它使用费城网页设计(PWD)答案的元素,并使用了欧文建议的hook_theme_registry_alter。使用此解决方案,您可以直接从自定义模块加载模板。

First, I added raw.tpl.php to a newly created 'templates' folder inside my module. The contents of raw.tpl.php are identical to PWD's page-ajax.tpl.php:

首先,我将raw.tpl.php添加到模块中新创建的“templates”文件夹中。 raw.tpl.php的内容与PWD的page-ajax.tpl.php完全相同:

<?php print $content; ?>

Next, I implemented hook_preprocess_page in my module in the same fashion as PWD (except that I modified the $_GET parameter and updated the template file reference:

接下来,我以与PWD相同的方式在我的模块中实现了hook_preprocess_page(除了我修改了$ _GET参数并更新了模板文件引用:

function MY_MODULE_NAME_preprocess_page(&$vars) {
    if ( isset($_GET['raw']) && $_GET['raw'] == 1 ) {
        $vars['template_file'] = 'raw';
    }
} 

Finally, I implemented hook_theme_registry_alter to add my module's 'templates' directory to the theme registry (based on http://drupal.org/node/1105922#comment-4265700):

最后,我实现了hook_theme_registry_alter,将我模块的'templates'目录添加到主题注册表中(基于http://drupal.org/node/1105922#comment-4265700):

function MY_MODULE_NAME_theme_registry_alter(&$theme_registry) {
   $modulepath = drupal_get_path('module','MY_MODULE_NAME');
   array_unshift($theme_registry['page']['theme paths'], $modulepath.'/templates');
}

Now, when I add ?raw=1 to the view's URL path, it will use the specified template inside my module.

现在,当我向视图的URL路径添加?raw = 1时,它将使用我的模块中的指定模板。

#4


5  

For others who may hit this page, if you're just working with standard callbacks (not necessarily views), this is easy. In your callback function, instead of returning the code to render within the page, use the 'print' function.

对于可能会访问此页面的其他人,如果您只是使用标准回调(不一定是视图),这很容易。在回调函数中,使用'print'函数,而不是返回要在页面内呈现的代码。

For example:

例如:

function mymodule_do_ajax($node)
{
    $rval = <<<RVAL
        <table>
            <th>
                <td>Data</td>
                <td>Data</td>
                <td>Data</td>
            </th>
            <tr>
                <td>Cool</td>
                <td>Cool</td>
                <td>Cool</td>
            </tr>
        </table>
RVAL;

    //return $rval; Nope!  Will render via the templating engine.
    print $rval; //Much better.  No wrapper.
}

Cheers!

干杯!

#5


3  

Another way to do it which I find very handy is to add a menu item with a page callback function that doesn't return a string:

我觉得非常方便的另一种方法是添加一个菜单项,其中包含一个不返回字符串的页面回调函数:

Example:

例:

/**
 * Implementation of hook_menu.
 */
function test_menu(){
  $items['test'] = array (
    /* [...] */ 
    'page callback' => 'test_callback',
    /* [...] */ 
  );
  return $items;
}

function test_callback() {
  // echo or print whatever you want
  // embed views if you want
  // DO NOT RETURN A STRING
  return TRUE;
}    

-- Update

- 更新

It would be much better to use exit(); instead of return TRUE; (see comment).

使用exit()会好得多;而不是返回TRUE; (见评论)。

#6


2  

Hey, here's yet another way of doing it:

嘿,这是另一种方式:

1) Download and install Views Bonus Pack (http://drupal.org/project/views_bonus) 2) Create a Views display "Feed" and use style "XML" (or something you think fits your needs better). 3) If you're not satisfied with the standard XML output, you can change it by adjusting the template for the view. Check the "theme" settings to get suggestions for alternative template names for this specific view (so you'll still have the default XML output left for future use).

1)下载并安装Views Bonus Pack(http://drupal.org/project/views_bonus)2)创建一个视图显示“Feed”并使用样式“XML”(或者你认为更适合你需要的东西)。 3)如果您对标准XML输出不满意,可以通过调整视图模板来更改它。检查“主题”设置以获取此特定视图的替代模板名称的建议(因此您仍将保留默认的XML输出以供将来使用)。

Good luck! //Johan Falk, NodeOne, Sweden

祝你好运! //瑞典NodeOne的Johan Falk

#7


2  

Based on answer of Philadelphia Web Design (thanks) and some googling (http://drupal.org/node/957250) here is what worked for me in Drupal 7 to get chosen pages displayed without the template:

根据费城网页设计的答案(谢谢)和一些谷歌搜索(http://drupal.org/node/957250),这是在Drupal 7中为我提供的,以便在没有模板的情况下显示所选页面:

function pixture_reloaded_preprocess_page(&$vars)
{
  if ( isset($_GET['vlozeno']) && $_GET['vlozeno'] == 1 ) {
        $vars['theme_hook_suggestions'][] = 'page__vlozeno';
  }   
}

instead of phptemplate, in D7 there has to be the name_of_your_theme in the name of the function. Also, I had to put two underscores __ in the php variable with the file name, but the actual template file name needs two dashes --

而不是phptemplate,在D7中必须有函数名称中的name_of_your_theme。另外,我不得不在php变量中添加两个带有文件名的下划线__,但实际的模板文件名需要两个破折号 -

content of page--vlozeno.tpl.php :

页面内容 - vlozeno.tpl.php:

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

The output, however, still has got a lot of wrapping and theme's CSS references. Not sure how to output totally unthemed data...

但是,输出仍然有很多包装和主题的CSS引用。不确定如何输出完全未经训练的数据......

#8


2  

Assuming you're in Drupal 6, the easiest way to do this is to put a phptemplate_views_view_unformatted_VIEWNAME call in template.php (assumes your view is unformatted - if it's something else, a list say, use the appropriate theme function). Theme the view results in this theme call then, instead of returning the results as you normally would, print them and return NULL. This will output the HTML directly.

假设您在Drupal 6中,最简单的方法是在template.php中放置一个phptemplate_views_view_unformatted_VIEWNAME调用(假设您的视图未格式化 - 如果是其他内容,则列表说,使用适当的主题函数)。然后将视图结果主题化为此主题调用,而不是像往常一样返回结果,打印它们并返回NULL。这将直接输出HTML。

PS - make sure to clear your cache (at /admin/settings/performance) to see this work.

PS - 确保清除缓存(在/ admin / settings / performance)以查看此工作。

#9


1  

there are probably a number of ways around this, however, the "easiest" may be just setting your own custom theme, and having the page.tpl.php just be empty, or some random divs

这可能有很多方法,但是,“最简单”可能只是设置自己的自定义主题,并且page.tpl.php只是空的,或者一些随机的div

// page.tpl.php
<div id="page"><?php print $content ?></div>

this method would basically just allow node.tpl.php to show (or any of drupal's form views, etc...) and would be an easy way to avoid modifying core, or having to alter the theme registry to avoid displaying page.tpl.php in the first place.

这个方法基本上只允许node.tpl.php显示(或任何drupal的表单视图等),并且是一种避免修改核心的简单方法,或者必须改变主题注册表以避免显示page.tpl .php首先。

edit: see comments

编辑:见评论

ok i played around with views a bit, it looks like it takes over and constructs it's own "node.tpl.php" (in a sense) for display within "page.tpl.php". on first glance, my gut feeling would be to hook into theme_registry_alter().

好吧,我玩了一些视图,看起来它接管并构建它自己的“node.tpl.php”(在某种意义上)在“page.tpl.php”中显示。乍一看,我的直觉就是挂钩到theme_registry_alter()。

when you're looking at a views page, you have access to piles of information here, as well as the page.tpl.php paths/files. as such i would do something like:

当您查看视图页面时,您可以访问此处的大量信息,以及page.tpl.php路径/文件。因此我会做类似的事情:

function modulejustforalteration_theme_registry_alter(&$variables) {
  if (isset($variables['views_ui_list_views']) ) {
  // not sure if that's the best index to test for "views" but i imagine it'll work
  // as well as others
    $variables['page']['template'] = 'override_page';        
  }
}

this should allow you to use a "override_page.tpl.php" template in your current theme in which you can remove anything you want (as my first answer above).

这应该允许您在当前主题中使用“override_page.tpl.php”模板,您可以在其中删除任何您想要的内容(作为我上面的第一个答案)。

a few things:

一些东西:

  • as i said, not sure if views_ui_list_views is always available to check against, but it sounds like it should be set if we're looking at a view
  • 正如我所说,不确定views_ui_list_views是否始终可用于检查,但听起来应该设置如果我们正在查看视图
  • you can alter the theme paths of the page array if you prefer (to change the location of where drupal will look for page.tpl.php, instead of renaming it altogether)
  • 如果您愿意,可以更改页面数组的主题路径(更改drupal查找page.tpl.php的位置,而不是完全重命名)
  • there doesn't appear to be any identifiers for this specific view, so this method might be an "all views will be stripped" approach. if you need to strip the page.tpl.php for a specific view only, perhaps hooking into template_preprocess_page() might be a better idea.
  • 此特定视图似乎没有任何标识符,因此此方法可能是“所有视图将被剥离”的方法。如果你只需要为特定视图剥离page.tpl.php,也许挂钩到template_preprocess_page()可能是个更好的主意。

#10


1  

I like the Drupal module. BUt, here's another way.

我喜欢Drupal模块。 BUt,这是另一种方式。

copy page.tpl.php in your theme folder to a new file called page-VIEWNAME.tpl.php, where VIEWNAME is the machine-readible name of the view.

将主题文件夹中的page.tpl.php复制到名为page-VIEWNAME.tpl.php的新文件中,其中VIEWNAME是视图的机器可读名称。

Then edit page-VIEWNAME.tpl.php to suit.

然后编辑page-VIEWNAME.tpl.php以适应。

#11


1  

There is also http://drupal.org/project/pagearray which is a general solution...

还有http://drupal.org/project/pagearray这是一个通用的解决方案......

Also, @Scott Evernden's solution is a cross site scripting (XSS) security hole. Don't do that. Read the documentation on drupal.org about how to Handle Text in a Secure Fashion http://drupal.org/node/28984

此外,@ Scott Evernden的解决方案是跨站点脚本(XSS)安全漏洞。不要那样做。阅读drupal.org上有关如何以安全时尚处理文本的文档http://drupal.org/node/28984

#12


1  

A simple way to display content of a special content-type you wish to display without all the stuff of the page.tpl.php:
Add the following snippet to your template.php file:

显示您希望显示的特殊内容类型内容的简单方法,无需使用page.tpl.php的所有内容:将以下代码段添加到template.php文件中:

function mytheme_preprocess_page(&$vars) {
  if ($vars['node'] && arg(2) != 'edit') {
      $vars['template_files'][] = 'page-nodetype-'. $vars['node']->type;
    }
}

Add a page-nodetype-examplecontenttype.tpl.php to your theme, like your page.tpl.php but without the stuff you don't want to display and with print $content in the body.

在你的主题中添加一个page-nodetype-examplecontenttype.tpl.php,就像你的page.tpl.php一样,但没有你想要显示的东西,并且在主体中有print $ content。

#13


0  

If I understand your question, you want to have nodes which contain all the HTML for a page, from DOCTYPE to </HTML>. What I would do is create a content type for those nodes -- "fullhtml" as its machine-readable name -- and then create a node template for it called node-fullhtml.tpl.php. You can't just dump the node's contents, as they've been HTML-sanitized. node.fullhtml.tpl.php would literally be just this:

如果我理解您的问题,您希望拥有包含页面所有HTML的节点,从DOCTYPE到 。我要做的是为这些节点创建一个内容类型 - “fullhtml”作为其机器可读的名称 - 然后为它创建一个名为node-fullhtml.tpl.php的节点模板。您不能只是转储节点的内容,因为它们已经过HTML清理。 node.fullhtml.tpl.php就是这样:

echo htmlspecialchars_decode($content);

Then you'll need a way to override the standard page.tpl.php. I think what you could do is at the top of your page.tpl.php check the $node's content type, and bail out if it's fullhtml. Or, set a global variable in node-fullhtml.tpl.php that page.tpl.php would check for.

然后你需要一种方法来覆盖标准的page.tpl.php。我认为你可以做的就是在你的page.tpl.php的顶部检查$ node的内容类型,如果它是fullhtml则挽救。或者,在page.tpl.php中检查的node-fullhtml.tpl.php中设置一个全局变量。

I'm no Drupal expert, but that's how I'd do it. I'm talking off the cuff, so watch for devils in the details.

我不是Drupal专家,但我就是这样做的。我正在谈论袖口,所以请注意细节中的恶魔。

#14


0  

I see you have already gone and made yourself a module, so this may no longer help, but it is fairly easy to get a view to expose an rss feed, which might be an easier way of getting at the content, especially if you want to include it on a different site.

我看到你已经离开并自己做了一个模块,所以这可能不再有用了,但是很容易获得一个暴露rss feed的视图,这可能是获取内容的一种更简单的方法,特别是如果你想要的话将其包含在其他网站上。

#15


0  

On D7 you can use menu_execute_active_handler

在D7上,您可以使用menu_execute_active_handler

$build = menu_execute_active_handler('user', FALSE);
return render($build);