1

I have a node type that I have a specific block added to. I have some AJAX going on in the block. When you view the full node the block shows up.

When I go to Views and render the full node content that block doesn't show up, just the node content.

How can I get the block to show up in Views when rendering the full node?

I've read that maybe Panels would be a better solution than using blocks, especially considering I'm using Views.

2
  • Have you considered using Layout Builder? I think your block is being rendered in the regions of your theme and not actually within the full node display. So Views isn't aware of that relationship.
    – tawellman
    Sep 27, 2020 at 4:53
  • I looked at Layout Builder and am just getting into it. I'm not sure how to use it for my purpose yet.
    – dca123
    Sep 28, 2020 at 17:58

1 Answer 1

2

You are mixing up full node (view mode) and single node (page, canonical URL). Blocks only get added to pages. In regions.

I'm not sure right now, but isn't there from core already a block reference field you can add to a node type? Use this. Or use the Block Field module. And then set your specific block as default value.

Alternatively you can use a pseudo field (a.k.a extra field) from a custom module to render your block. Has the advantage that it then can't be changed by editors.

4
  • 1
    Ok, yes I was not clear on that distinction. I'll check out the Block Field module since at the moment discussion about core functionality seem to point to it anyway. I haven't used a pseudo field in a custom module so I'll look into that. Since I have a custom module and I don't want people messing with it, that would make the most sense.
    – dca123
    Sep 28, 2020 at 17:57
  • I've used the Block Field module and the block is displayed. Now, I'd like to alter the block content in a custom module. I can alter the block content on the single node, but not in Views. Do I need to use hook_entity_view_alter?
    – dca123
    Sep 28, 2020 at 23:41
  • * hook_ENTITY_TYPE_view_alter
    – dca123
    Sep 29, 2020 at 0:08
  • 1
    @dca123 – Yeah, hook_block_view_alter or maybe even hook_block_access, depends on what exactly you want to achieve. Might be a good candidate for a new question.
    – leymannx
    Sep 29, 2020 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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