I am trying to create a Paragraph type that lets a user specify a node to reference, and a couple of checkboxes that influence how content from that node is rendered.

I can create a view that gets me the resulting node's Paragraph item that I am after, but how do I influence how certain things are rendered or not rendered from another Paragraphs field values? Would it be easier to load the node instead of use a View, and pass a flag into the render process somehow and "see" it in node preprocess and/or get the Paragraph id from the node, and do the same (rendering wise)?

  • The node is rendered and cached independently from the parent paragraph. The trick is to remove the cache keys, see @Berdir's answer to this question drupal.stackexchange.com/questions/193494/… – 4k4 Nov 8 '19 at 16:55
  • Oh hm.. in this case I am really after a paragraph on the referenced node. Based on paragraph fields from where I am trying to reference said node, I want to change the paragraph being output. Does that still remain true? – Kevin Nov 8 '19 at 19:34
  • OK, one step after the other. The first step is about getting the paragraph field values into the node template. What you do then with that information to control the output of node fields is a different question. – 4k4 Nov 8 '19 at 19:53
  • Use a view mode to render the node and a custom field formatter for the paragraph. In the field formatter get the paragraph's parent entity (the node) and from there the other paragraph and its values and use that to define output. Maybe? – leymannx Nov 10 '19 at 19:47

Your Answer

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

Browse other questions tagged or ask your own question.