Dear everyone

I have been developing a site with Drupal 8 and it has gone (surprisingly) smoothly.

The site is built on paragraphs entities of different kinds stacked at user's will on top of each other.

But now I got stuck on something I can't understand even if there are all kinds of hints all around.

I have one paragraph entity which requires a heavier processing and I have implemented a module to handle it (only stub so far).

Could somebody point out how to organize the modules, twig templates, possibly/probably needed pre-processor functions. I seem to be quite confused what goes and where.

This is my tree so far (only relevant files in tree structure shown). I have built this as a multi-site (it shouldn't affect the answer but who knows).

  site.net
    themes
       sitetheme
          templates
              paragraph--my-apps.html.twig
    modules
        hard_work
           hard_work.module
           src/          
             Controller
                 HardWorkController.php
              Plugin
                 Block
                   HardWorkBlock.php
           templates
              hard-work.html.twig 
              hard-work-block.html.twig
          

I sort of think I have all the apparatus needed but seem to have lost the clue how to connect the parts to each other. I also think I know what to write, but still don't know WHERE should I write those magic lines and what are the names of pre-process functions etc.

The idea is to embed the contents of hard-work-block.html.twig into paragraph--my-apps.html.twig

I understand that this is a bit sparse definition but I am more looking for structure than the actual code lines. If I have missed the perfect article on Drupal site or somewhere in the Googleland, I am as well happy for the pointers.

Please bear me

hank

Comments

Shashwat Purav’s picture

Check the link below:

Create custom twig templates from custom module

This might help.

Thank You,
Shashwat Purav

hcape’s picture

Thank you Shashwat

Unfortunately that was one piece of the jigsaw puzzle I already had and still I don't get the "full" picture of everything. Maybe I am just dumb :P

I have to do something else right now, but I'll try to re-read that article again later and hopefully get a better grasp of the structure.

I appreciate your input :)

hank

hcape’s picture

Actually, trying to solve this I think I got ome grasp what goes where but now that I have tried to add a template preprocessor in sitetheme.theme but it doesn't seem to be fired though I have read an re-read the function name many times.

my sitetheme.theme file (in themes/sitetheme) is as follows:

<?php
  function sitetheme_preprocess_paragraph__my_apps(&$variables) {
    $variables['testing'] = "<h2>Testing testing</h2>";
    file_put_contents("/tmp/preprocess.debug","Came here at least");   // just to check if this gets fired
  }

Any ideas what might be wrong, why the preprocessor isn't firing? Or how to debug it?

The my_apps is a valid paragraph type and currently I am not yet even referencing the hard_work module. The paragraph--my-apps.html.twig works fine (which proves in my mind that paragraph__my_apps is fine) but doesn't get the variable from preprocessor (obviously not, if it is not fired)

It is a bit frustrating when something just doesn't seem to work, though everything should be right... :/

hank

hcape’s picture

Actually the file_put_contents wasn't working - replacing it with echo showed that the pre-processor was working.

And really got it working after understanding that the variable wasn't content.testing but just testing.

Hopefully this concludes this thread :)

hank