简体   繁体   English

在Drupal中创建新页面

[英]Create new page in drupal

Iam new in drupal. Iam在Drupal中是新手。 I want to create a page and want to add data in page directly with out using backend content. 我想创建一个页面,并想在不使用后端内容的情况下直接在页面中添加数据。 I have created a page like this, page-test.tpl.php. 我已经创建了一个类似页面page-test.tpl.php。 How can I call this newly created page in browser? 如何在浏览器中调用此新创建的页面?

First you have to create your own custom module.Let the module name be test.Create 2 files namely test.info and test.module.Declare a hook_menu function inside the test.module file.Since your module name is test your hook_menu will be named as test_menu . 首先您必须创建自己的自定义模块,让模块名称为test。创建两个文件test.info和test.module。在hook_menu文件中声明一个hook_menu函数。由于您的模块名称为test,因此hook_menu将为命名为test_menu Hook_menu enables modules to register paths in order to define how URL requests are handled. Hook_menu使模块可以注册路径,以定义如何处理URL请求。 Paths may be registered for URL handling only, or they can register a link to be placed in a menu. 路径只能注册用于URL处理,或者可以注册要放置在菜单中的链接。

Test.module 测试模块

function test_menu() {
  $items = array();
  $items['test'] = array(
    'title' => 'My Page',
    'description' => 'Study Hard',
    'page callback' => 'test_simple', //Calls the function
    'access arguments' => array('access content'),
  );
  return $items;
}   

function test_simple() {                                                                                                                                                                                                             
  return array('#markup' => '<p>' . t('My Simple page') . '</p>');
}

Test.info Test.info

name = Test
description = Provides a sample page.
core = 7.x

After adding this try clearing the drupal cache and then navigate to /test .Try this link if you are a beginner.Try reading hook_theme which allows you to use your custom template.More about hook_theme here .Hope it might help u mate.. :) 添加此内容后,尝试清除drupal cache ,然后导航到/test如果您是初学者,请hook_theme链接。尝试阅读hook_theme ,它可以使用您的自定义模板。有关hook_theme更多信息, hook_theme 这里可能对您有所帮助..: )

Pages in drupal are stored in the database, not in actual code files like old websites used to. drupal中的页面存储在数据库中,而不是像过去的旧网站那样存储在实际的代码文件中。 The template files (.tpl.php) are exactly that - templates. 模板文件(.tpl.php)就是模板。 So for example, lets say you have blog content. 例如,假设您拥有博客内容。 You'd have to create a content type of 'Blog'. 您必须创建“博客”的内容类型。 you could then create a template file (ex. node--blog.tpl.php) which would format the way the blog pages would look. 然后,您可以创建一个模板文件(例如node--blog.tpl.php),该文件将格式化博客页面的外观。 But you would still need to add new pages through the drupal interface in order to add them to the site. 但是您仍然需要通过drupal界面添加新页面才能将其添加到站点。 You could always use an input type of PHP if you'd like to include php in the body of the page. 如果要在页面正文中包含php,则可以始终使用PHP的输入类型。

If you simply want to display a php file in your browser from your site, you can just upload a php file of your choice to your sites/default/files directory and access it directly via the file path. 如果您只想在网站上的浏览器中显示一个php文件,则只需将您选择的php文件上传到您的sites / default / files目录,然后直接通过文件路径访问即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM