0

I am trying to get the value of a field that is displayed in a panel page. I might be going about this all wrong, because I'm still getting used to Drupal 8. I want to display book information, including the ISBN value, which I use to make a link to Amazon.

I first tried a node template: node--book_page.html.twig and was able to do it by inserting the value of {{ content.field_isbn10.0 }} into the URL I added to the twig. This worked great, but when I tried doing the same thing to the template that I set up to be used by the panel page, nothing happens.

I know I have the custom layout twig working as it should, but I'm guessing that there is more to requesting the value than {{ content.field_isbn10.0 }} now that it's going through node_view in Panels.

I have tried adding it to the panel page as entity_field:node:field_isbn10 as well as field_block:node:book_page:field_isbn10. I just can't seem to get how to access the ISBN field value like I did in the node template.

Here's what shows using kint: enter image description here

Here's the top of that knit: enter image description here

  • This kint snippet looks like an entity field. So {{ ?.?.?.field_isbn10.value }} should work, if you add the three levels above the field not shown in the screenshot. – 4k4 Oct 22 '18 at 6:30
  • The question title about a panel page is confusing, I assumed the node would be nested deeper. Now it looks you have a node template where you can access node fields directly {{ node.field_isbn10.value }}. – 4k4 Oct 23 '18 at 10:12
  • I added the top of the knit tree so it can be seen now. I'm trying to display a node in a panel page using node_view. I set up my own twig so I can add the links to Amazon mainly because that's how I did it on D7. I guess if I was better, I could do the same thing using a custom module, but I haven't got that far yet. All I'm basically doing is generating a link to Amazon that adds the book ISBN number to the link. The link works fine if I don't use panels node_view and leave it as a node, and I add a custom node type twig. – TomP Oct 23 '18 at 15:23
  • Any solution for this? Even I am facing the same issue – Kiran Feb 5 at 12:50
0

I can't see the field parents on that devel output, but as far I know it is done like this,

{{ content._row.entity.field_isbn10.value }}

That should print out the field value.

  • I added the top of that knit column. I what was suggested, both with .value and .0 but neither worked. Here is the line I'm using to test it out with in my twig. {% if content.col_2|render|trim is not empty %} <div class="atl__lc lc-2"> {{ content.col_2 }} <p>Amazon: {{ content._row.entity.field_isbn10.0 }}</p></div>{% endif %} – TomP Oct 22 '18 at 14:46
  • Sorry. I can't seem to make code in my comment work – TomP Oct 22 '18 at 14:54
  • Did you try my code – Jdrupal Oct 22 '18 at 14:54
  • Jdrupal Yes I did. My test is just a simple line added to the twig.: <p>Amazon: {{ content._row.entity.field_isbn10.value }}</p> – TomP Oct 22 '18 at 15:01
  • The word "Amazon:" prints out but nothing else – TomP Oct 22 '18 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.