0

I have recently converted from Joomla to Drupal. I am still learning how to use it but I can't seem to find answers (esp for Drupal 9 not some ancient version usually coming up with google search) how to have same functionality of "loadposition" and "loadmodule" in Joomla, but in Drupal 9?

In Joomla, {loadposition} and {loadmodule} allows to embed modules / blocks (modules in Joomla, in Drupal I think those are called Blocks) inside an article (node) content. So that way you can call a block logic and code anywhere within an article (node) by simply adding {loadposition} to the code. Example:

I have a module (block) that displays a list of recent posts I have made. Let's call it "Recent Posts". And I want to include it on the "home page" and I also want to include it in the "blog". And I don't mean it in general, like just assigning it, but to load it precisely in that part of the code where I target it.

Recent posts module / block (aka {loadmodule recentpost} contains code:

// bla bla bla Recent Posts code

Homepage is made like this:

// bla bla bla homepage html

Blog page html:

// bla bla bla blog html

Now, let's say I want to add the recent posts code at the bottom of the content within the homepage content region, but at the same time I want to add it on the top of code before the main content code on the blog page html.

In Joomla it would end up like this:

Homepage + module / block :

// bla bla bla homepage html
{loadmodule recentpost}

Blog page + module / block :

{loadmodule recentpost}
// bla bla bla blog html

How to do this in Drupal 9? What is the equivalent of Joomla's {loadposition} and {loadmodule} in Drupal 9?

More info about {loadposition} and {loadmodule} here: https://docs.joomla.org/How_do_you_put_a_module_inside_an_article?

4
  • Most common approach for content in nowadays Drupal is to use Paragraphs to build your content modularly like in WordPress' Guttenberg Editor. Then you have a paragraph type "Text", a paragraph type "Image", a paragraph type "Text and Image" and so on. And you add them to the page in any desired order you want. What about a paragraph type "Block Reference" which contains a block reference field that lets you add any block you want in any position in the content?
    – leymannx
    Commented Jun 8, 2021 at 6:41
  • @leymannx Hi thanks for chiming in! Sounds promising, is this what you are talking about? youtube.com/watch?v=73uepd9CLFI Also, is there a limitation on the type of blocks that this would work with? Or does it work for blocks like menus etc too?
    – user104683
    Commented Jun 8, 2021 at 7:09
  • No I'm talking about just Paragraphs which lets you create paragraph types which then can be added one by one to a node into a let's say field_content_paragraphs, and one paragraph type could be named "Block" which contains a Block Field that's lets you reference a block on any position within the field_content_paragraphs of a node. Only thing you might pay attention to I think was it only can reference block which has been placed at the Structure > Block page (maybe in a "Hidden" region). Try it out
    – leymannx
    Commented Jun 8, 2021 at 7:58
  • Hi, leymannx. Thank you for help. I have not even installed Paragraphs yet, but I think yours is the answer. And I mean the "Block Field" part. Installing Block Field and using Layout Builder, and ofc Paragraphs later on which will possibly enhance it further, seems to give exactly that functionality as {loadposition} and {loadmodule} would in Joomla. I can add menus, add login forms, any block, inside an article this way. Please write an answer leymannx so I can accept it as the correct one. :)
    – user104683
    Commented Jun 9, 2021 at 17:32

1 Answer 1

0

You can use the Entity Embed module coupled with the Entity Browser module to create similar functionality. These modules will produce a UI solution rather than a shortcode type solution - the result will be very similar to how media is embedded.

Read the Entity Browser documentation and create a new browser to select your blocks (or whatever kind of entities you want). Then create a new Embed button and add it to your WYSIWYG as documented on the Entity Embed project page / module README.

2
  • Hi sonfd. Thank you for your suggestion. I have tried Entity Browser and Entity Embed. But the way I understand it, and correct me if I'm wrong, this only makes an iframe for another article. I couldn't find how to embed things like menus or other "blocks". And the way {loadposition} and {loadmodule} work in Joomla, they allow to place any block (called module in Joomla, which could be a custom HTML block, a menu, a login form, a language switch, a contact form, a video player, a recent articles feed etc). So maybe I am using your solution wrong?
    – user104683
    Commented Jun 9, 2021 at 17:29
  • No, they don't make an iframe. One of the widgets used to select which item to place uses an iframe, but the content in the WYSIWYG is real rendered content.
    – sonfd
    Commented Jun 9, 2021 at 20:43

Your Answer

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