Sono pienamente consapevole come fare questo in Drupal 7 in modo vi spiegherò quello che farebbe normalmente utilizzando Drupal 7.variabili Passando alla ramoscello utilizzando hook_theme all'interno di un modulo
Quando si effettua un modulo personalizzato che uso hook_theme un molto, è molto potente e riutilizzabile!
/**
* Implements hook_theme().
*/
function MODULE_theme() {
$themes = array();
$themes['name_of_theme'] = array(
'path' => drupal_get_path('module', 'module') .'/templates',
'template' => 'NAME_OF_TEPLATE',
'variables' => array(
'param1' => NULL,
'param2' => NULL,
),
);
return $themes;
}
Vorrei poi chiamo questo tema utilizzando
theme('name_of_theme', array(
'param1' => 'VALUEA',
'param2' => 'VALUEB'
));
Questo sarebbe poi tornare html e sarei felice.
Quindi Drupal 8 è fuori necessità di fare i conti con esso.
/**
* Implements hook_theme().
*/
function helloworld_theme() {
$theme = [];
$theme['helloworld'] = [
'variables' => [
'param_1' => [],
'param_2' => 'hello',
]
];
return $theme;
}
e dentro il mio controller sto sto usando
$hello_world_template = array(
'#theme' => 'helloworld',
'variables' => [
'param_1' => 'hello world',
'param_2' => 'hello from another world'
],
);
$output = drupal_render($hello_world_template,
array(
'variables' => array(
'param_1' => $param_1,
'param_2' => $param_2,
)
)
);
return [
'#type' => 'markup',
'#markup' => $output
];
sto ottenendo un'uscita del mio modello, tuttavia ciò che Im non sicuro circa è dove far passare i miei parametri in modo che siano disponibili nel mio modello (solo per segnalare che le mie variabili sono disponibili sono nulle come definito in hook_theme)
Sono anche aperto all'idea che potrei fare il fondamentalmente sbagliato e sono aperto a un'alternativa percorso se il mio metodo non è la migliore pratica.
Btw. Dovresti usare '\ Drupal :: service ('renderer') -> renderRoot()' invece di deprecato 'drupal_render()'. – kenorb