In my Drupal 8 site, I am developing a custom block in my module custom, with some text and some images. I created a template, and everything works fine. Now I need to add some images for my custom block, and I don't know how to pass the base URL to call those images.
In Drupal 7 I used the following code.
function bloques_block_view($delta = '') {
$block = array();
$ruta = $GLOBALS['base_url'] . '/' . drupal_get_path("module", "mymodule");
$link = $GLOBALS['base_url'] ;
switch ($delta) {
//footer
case 'footer':
$block['subject'] = '';
$block['content'] = leer_template('footer.tpl', array('%ruta%' => $ruta, '%link%' => $link));
break;
}
return $block;
}
Everything works well, but in Drupal 8 it is a little different. The problem comes with build()
.
public function build() {
$ruta = 'holamundo',
return array(
'#theme' => 'mymodule',
'#title' => 'my title ',
'#ruta' => '<p>' . $ruta . '</p>'
);
}
Just the title works in the template file; $ruta
is not working.
<h2>My Custom Block {{ title }}-{{ ruta }}</h2>
I don't know if this is the correct way to declare the base URL (just like I did in Drupal 7).
$ruta = $GLOBALS['base_url'] . '/' . drupal_get_path("module", "bloques");