Skip to main content
added 63 characters in body
Source Link

I have a page(node) with a certain ID. On the front page, I want to pull a field called field_image1 and field_link1.

To do that I added the following to my themename.theme:

use Drupal\node\Entity\Node;

function themename_preprocess_nodethemename_preprocess_page(&$variables) {

    $vanilla_spice$variables['vanilla_spice'] = Node::load(61);

    $variables['variable'] = "tetsing the variable";

}

page--front.html.twig:

{{ kint(vanilla_spice) }}
{{ kint(variable) }}

When I visit the page, the variable is null :(

How can I load this information inside the variable?

Note: I based myself in this answer here, but even if I assign a normal string to the vanilla_spice variable

$vanilla_spice = "tetsing the variable";

I still see a null.

I have a page(node) with a certain ID. On the front page, I want to pull a field called field_image1 and field_link1.

To do that I added the following to my themename.theme:

use Drupal\node\Entity\Node;

function themename_preprocess_node(&$variables) {

    $vanilla_spice = Node::load(61);

}

page--front.html.twig:

{{ kint(vanilla_spice) }}

When I visit the page, the variable is null :(

How can I load this information inside the variable?

Note: I based myself in this answer here, but even if I assign a normal string to the vanilla_spice variable

$vanilla_spice = "tetsing the variable";

I still see a null.

I have a page(node) with a certain ID. On the front page, I want to pull a field called field_image1 and field_link1.

To do that I added the following to my themename.theme:

function themename_preprocess_page(&$variables) {

    $variables['vanilla_spice'] = Node::load(61);

    $variables['variable'] = "tetsing the variable";

}

page--front.html.twig:

{{ kint(vanilla_spice) }}
{{ kint(variable) }}

When I visit the page, the variable is null :(

How can I load this information inside the variable?

Note: I based myself in this answer here, but even if I assign a normal string to the vanilla_spice variable

$vanilla_spice = "tetsing the variable";

I still see a null.

Source Link

Accessing contents of a node id not working in .theme file

I have a page(node) with a certain ID. On the front page, I want to pull a field called field_image1 and field_link1.

To do that I added the following to my themename.theme:

use Drupal\node\Entity\Node;

function themename_preprocess_node(&$variables) {

    $vanilla_spice = Node::load(61);

}

page--front.html.twig:

{{ kint(vanilla_spice) }}

When I visit the page, the variable is null :(

How can I load this information inside the variable?

Note: I based myself in this answer here, but even if I assign a normal string to the vanilla_spice variable

$vanilla_spice = "tetsing the variable";

I still see a null.