Create simple page with complex elements within the text

I hope this question is not too silly or simple.

I’m currently trying to create a page that contains a lot of simple text and sometimes some complex elements like a image slider between the text blocks. These objects need quite a lot of custom HTML code.

I have studied the documentation and came up with these options:

  1. Create a normal page and add the HTML code in the markdown editor between the normal text blocks - which seems a bit ugly to me
  2. Use the modular page feature. But as far as I understand I then would need to create modules for every block in the page, so in case of following setup: text, slider, text, slider, text I need to create 5 subfolders for each block and then include these blocks in the parent page with the content configuration.

The second option is probably the preferred one but in my opinion this creates a bit of an overhead to create a module for each simple text block.

My idea would be to create a simple page for the text and then kind of “include” the complex elements in the editor and pass some parameters to customize the slider element. But I did not find anything in the docs that support my idea.

Am I missing something or do you have a better idea how to create a page structure like this?

1 Like

@deflox, I think the modular route would be the most simple one. It would make editing of the page more easy then a large chunk of “complex” html mixed with Markdown.

An alternative option could be creating a custom shortcode with which you can pass all required parameters for the slider. Although this will cleanup the page’s markdown, it will need custom code which might be a bit overkill. Unless you can reuse the custom shortcode in other pages, or if like coding of course…

A page could then look like:

markdown text1

[complex-element param1 param2 param3 /]

markdown text2

[complex-element param4 param5 param6 /]

markdown text3

Thanks for your suggestion. The custom shortcode option looks promising, I will take a look at it.

In the meantime, I also did some more research myself and found the page-inject plugin. There it is possible to also include modular elements directly in the markdown of a page. As I’m also developing my own theme, this option looks also very promising for me as I then just create a module template for complex elements and then create modules for the page which I just include using this plugin in the text part of the page. And I will just use the frontmatter part of the module to customize its behavior.

@deflox, There is never a single solution when using Grav… Pick the one that works best for you.

Also, please share the solution that works best for you here on the forum for the benefit of the entire community.