Hi Drupal community!
Super loving D8 but still getting my head around a few things.
Mainly accessing field values from paragraph preprocess functions. Here is the bit of code I have inside my base.theme file:
function base_preprocess_paragraph(&$variables) {
$paragraph = $variables['paragraph'];
$variables['heading'] = $paragraph->field_heading->get(0)->value;
}This does, indeed, give me access to this variable in my template file. (meaning {{ heading }} prints the correct value)
However, while the specific paragraph prints to the screen, nothing else get printed. Even the <head> is completely empty!
Got a few questions:
1) Is this even the right way to be accessing the field values? NOTE: I tried the getValues() method and got the same issue as above.
2) How would I manually drill down to the value?
3) Any other thoughts/best practices?
Thanks!
-=b=-
Comments
Comment #2
scottsawyerThis is an old issue, but in case you haven't found a solution, it may just be a plain PHP error. You are not checking to see if that paragraph field exists or whether it has a value before you set the variable.
Comment #3
berdirYes, sounds like a php fatal error that aborts. Always develop with verbose error logging.