Drupal 8 Drupal 8-如何覆盖内容';自定义模块中的模板?
在看了一堆模块之后,我仍然对如何获取我创建的内容块(服务器)、制作我自己的自定义模块(服务器)并执行一些逻辑以便将其传递到服务器模板感到困惑 servers.info.ymlDrupal 8 Drupal 8-如何覆盖内容';自定义模块中的模板?,drupal-8,Drupal 8,在看了一堆模块之后,我仍然对如何获取我创建的内容块(服务器)、制作我自己的自定义模块(服务器)并执行一些逻辑以便将其传递到服务器模板感到困惑 servers.info.yml name: Servers Module description: Creates a Servers Module package: Servers type: module core: 8.x servers.module <?php function servers_theme(){ $theme[
name: Servers Module
description: Creates a Servers Module
package: Servers
type: module
core: 8.x
servers.module
<?php
function servers_theme(){
$theme['server_page'] = [
'variables' =>['name' => NULL],
'template' => 'server',
];
return $theme;
}
控制器
#located in servers/src/controller/Servers.php
namespace Drupal\Servers\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* Controller for js_example pages.
*
* @ingroup js_example
*/
class Servers extends ControllerBase {
/**
* Accordion page implementation.
*
* We're allowing a twig template to define our content in this case,
* which isn't normally how things work, but it's easier to demonstrate
* the JavaScript this way.
*
* @return array
* A renderable array.
*/
public function getServersImplementation($name)
{
return[
'#theme'=>'server_page',
'#name'=>$name,
];
}
}
当我启用模块时,绝对没有显示任何内容。我知道它是启用的,因为我可以将路由路径更改为节点id/node/93,并且该节点将给我一个页面未找到错误,如果没有路由,我可以获取内容
error.log或最近的日志消息中不存在错误。我对D8中的这一点很困惑,但一旦我能理解这个概念,我知道我将能够理解完成我的模块所需的所有内容
提前感谢。控制器收到的参数应与路由文件中的参数同名。此外,此控制器未使用实体类型。服务器是否为节点内容类型?还是一种新的实体类型?
#located in servers/src/controller/Servers.php
namespace Drupal\Servers\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* Controller for js_example pages.
*
* @ingroup js_example
*/
class Servers extends ControllerBase {
/**
* Accordion page implementation.
*
* We're allowing a twig template to define our content in this case,
* which isn't normally how things work, but it's easier to demonstrate
* the JavaScript this way.
*
* @return array
* A renderable array.
*/
public function getServersImplementation($name)
{
return[
'#theme'=>'server_page',
'#name'=>$name,
];
}
}