45
loading...
This website collects cookies to deliver better user experience
drupal
console command in order to create a new module:drupal generate:module
├── MACHINE_NAME_MY_MODULE.info.yml
├── MACHINE_NAME_MY_MODULE.module
├── composer.json
└── templates
└── MACHINE_NAME_MY_MODULE.html.twig
drupal module:install MACHINE_NAME_MY_MODULE
drupal generate:controller
├── MACHINE_NAME_MY_MODULE.routing.yml
└── src
└── Controller
└── CONTROLLER_NAME.php
generate:controller
command.Implement method: METHOD_NAME
public function content() {
return [
'#type' => 'markup',
'#markup' => $this->t('Implement method: content')
];
}
public function content() {
return [
'#theme' => 'MACHINE_NAME_MY_MODULE'
];
}
function MACHINE_NAME_MY_MODULE_theme() {
return [
'MACHINE_NAME_MY_MODULE' => [
'render element' => 'children',
'variables' => [
'var1' => '',
'items' => []
]
],
];
}
public function content() {
$var1 = 'Hello world!';
$array1 = [1, 2, 3, 4];
return [
'#theme' => 'MACHINE_NAME_MY_MODULE',
'#var1' => $var1,
'#items' => $array1,
];
}
drupal cc
<div>
<p>{{ var1 }}</p>
{% for item in items %}
{{ item }}
{% endfor %}
</div>
requirements:
_permission: 'access content'
requirements:
_permission: 'access content'
_role: 'authenticated'
requirements:
_permission: 'access content'
_role: 'authenticated, editor'
requirements:
_permission: 'access content'
_role: 'authenticated'
options:
no_cache: TRUE