无主题页面 - 或仅限内容的内容类型

时间:2011-09-21 19:20:07

标签: drupal-7

我需要创建仅输出我输入的内容,没有布局,没有评论,块等的内容。

如果我可以实现一个使用可能有用的空白模板的自定义内容类型,但是我已经无法使其工作到覆盖主题似乎替换了网站范围内的所有内容。所以,跳过它,是否有一种我不知道的简单方法,只输出我在内容体中输入的内容,没有布局/块/注释等。

是否可以通过自定义模块在底部添加自定义字段,然后在process_page()挂钩期间忽略主题和布局并输出内容?

请不要建议“视图”,因为它不稳定。

一些示例用例:

一个PHP类型的页面,它只是一个我不想以布局为例的脚本。

或者如果我有一些json数据要返回。

或者,如果我想用它自己的主题折腾一个多功能的页面。

有什么建议吗?

1 个答案:

答案 0 :(得分:2)

我正在开发一个模块,它将执行此操作并与视图集成,因此您可以将视图设置为“无主题”。我有它,它将在节点表单上创建一个复选框,您可以将该节点指定为无主题节点。选中后,将显示没有主题的节点(仅限内容,无标题)。

这有点hackish,但它初步工作。我将根据自己的需要充实这一点,并且随着时间的推移,我也可能会将其与观点结合起来。

timeless.install

<?php

/**
 * themeless.install
 * defines our schema for flagging nodes as being themeless or not.
 */

function themeless_schema() {
  $schema['themeless_node'] = array(
    'description' => 'Keeps track of which nodes are themeless.',
    'fields' => array(
      'nid' => array(
        'description' => 'The node id of a themeless node',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'primary_key' => array('nid'),
  );
  return $schema;
}

function themeless_enable() {
  if (db_table_exists('themeless_node') == FALSE) {
    drupal_install_schema('themeless');
  }
}

function themeless_uninstall() {
  drupal_uninstall_schema('themeless');
}

timeless.module     

function themeless_process(&$variables, $hook) {
  if ($hook == 'page') {
    if (isset($variables['page']['content']['system_main']['nodes']) && is_array($variables['page']['content']['system_main']['nodes'])) {

      $node = $variables['page']['content']['system_main']['nodes'];
      $nodes = array_keys($node);
      $result = db_query("SELECT t.nid AS themeless, n.promote
                             FROM {themeless_node} t, {node} n
                             WHERE t.nid=:nid
                               AND n.nid=t.nid",
                             array('nid' => $nodes[0]));
      $tdata = $result->fetchObject();      
      if (isset($tdata->themeless) && $tdata->themeless > 0 && $tdata->promote != 1) {
        if ($node[$nodes[0]]['body']['#object']->body['und'][0]['format'] == 'php_code') {
          print $node[$nodes[0]]['body'][0]['#markup'];
        } else {
          print $node[$nodes[0]]['body']['#object']->body['und'][0]['value'];
        }
        exit();
      }
    }
  }
}

function themeless_form_alter(&$form, &$form_state, $form_id) {

  $parts = explode('_',$form_id);
  $form_type = $parts[count($parts)-1].'_'.$parts[count($parts)-2];
  $themeless = '';

  if ($form_type == 'form_node') {
    if (isset($form_state['node']->nid) && $form_state['node']->nid) {
      $themeless = db_query("SELECT COUNT(*) AS themeless
                             FROM {themeless_node}
                             WHERE nid=:nid",
                             array('nid' => $form_state['node']->nid))->fetchField();
    }
    $checked = ($themeless == 1) ? 'checked' : '';
    $form['themeless'] = array(
      '#type' => 'fieldset',
      '#title' => t('Themeless Node'),
      '#weight' => 5,
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['themeless']['themeless_node'] = array(
      '#type' => 'checkbox',
      '#title' => 'Themeless Node',
      '#description' => 'This theme will be displayed without any wrapper themes.',
      '#weight' => 100,
      '#default_value' => $themeless,
    );
  }
}

function themeless_node_insert($node) {
  $result = db_query("INSERT INTO {themeless_node} (nid)
                      VALUES( :nid )",array('nid' => $node->nid));
}

function themeless_node_update($node) {
  if ($node->themeless_node == 1) {
    if (db_query("SELECT COUNT(*) AS themeless
                  FROM {themeless_node}
                  WHERE nid=:nid",
                  array('nid' => $node->nid))->fetchField() != 1) {
      $result = db_query("INSERT INTO {themeless_node} (nid)
                          VALUES( :nid )",array('nid' => $node->nid));
    }
  } else {
    $result = db_query("DELETE FROM {themeless_node}
                        WHERE nid=:nid",array('nid' => $node->nid));
  }
}

timeless.info

name = Themeless
description = Gives the option to a node to have a themeless display or displayed without the various theme templates native to Drupal.
core = 7.x
version = 7.x-1.0dev