Dynamic block alter/creation with custom field

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
jcastelli's picture

Hello all,

Still relatively new to Drupal, coming from WordPress. My objective is to allow my content editors to edit a "See Also" field on my custom content type, "Product," and have it appear in a "See Also" block in the sidebar region.

I've done similar things in the content block itself, grabbing the content I need out of the render array and using it to populate tabs. I essentially want to do the same here, but render this particular field in a block.

Ideally, I want to create the block on the fly, but haven't found a way to do that from the theme layer. I don't want to write it to the database, only render it as a block.

I was leaning toward leaving the empty block in my hidden region (alongside hidden forms), then, if the field is not empty, populate it with the content of the field and move it to the sidebar. The reason being that I've learned how to do most of this, and it seems it'll work. I can think of a couple other approaches that may work, but I really want to learn the best practices in hopes of ultimately becoming a contributing member of the community.

My worry with that approach is that Google will dock me for having this empty block, or, at best, a hidden block containing links, relevant or not.

My main goal is to hear from a Drupal vet on the subject. I'm still getting a feel for the Drupal Way, and just a couple of broad hints pointing me in the right direction on this would be great!

Thanks in advance for any guidance.