Creating optional text sections for user in the Panel

I might be overlooking something here, but I am using the kirby-modules plugin and attempting to create modules that have optional text sections within them. I want the user to be able to decide when and where to add different “tip” sections within the module (and/or photos as well). How might this be achievable? Blueprints?

This is an example of what I want the user to be able to choose to add as many times as they want within the module on the panel.

<div class="my-3 <?= $module->moduleId() ?>" id="<?= $module->uid() ?>">
  <div>
    <span class="tool-tip">TIP:</span>
    <span><?= $module->text()->kirbytextinline() ?></span>
  </div>
</div>

Just to clarify: You want to have these sections within a modules, not as separate modules?

How about using a blocks field with predefined custom blocks inside a module?

1 Like

Just to clarify, I am making a long form manual. From the panel, within a section, the user should be able to choose from three different modules (each different module is only indented farther than the first). Within that module I want to be able to add a text section with a specific color headline and text below, AND/OR be able to add an image, AND/OR be able to add a “Tip” text section with specific styling different than the headline/text section. The blocks seem to be the right direction because then they can drag and drop the order within the module.

I have been experimenting with the blocks and can’t figure out how to properly display the blocks info onto the page. It keeps outputting an array in string form. I apologize if this isn’t the best description as I am new to Kirby 3.

Hm, without seeing any code, hard to tell what’s wrong.

1 Like

In my text.php file that is a module

<div class="my-3">
  <div>
    <?php if ($module->blocks()->isNotEmpty()): ?>
      <?= $module->blocks()->toHtml() ?>
    <?php endif?>
  </div>
</div>

and it outputs

[quote=“yip, post:5, topic:22820”]

Should be

 <?= $module->blocks()->toBlocks() ?>

See the documentation about the blocks field:

1 Like

Haha, wow, I swear I tried that, but it is working now. Thank you!!!

To my other question, if I want to have two different styled text blocks, how would this be achievable? Would I have to make custom blocks? Can you edit the default options for the blocks?

Either a complete custom block, or you can overwrite the text block yaml file in /site/blocks/text.yml and add additional fields. Then create a new /site/blocks/text.php snippet where you apply classes etc. for the different styles.

(the example in the docs does it directly in the blueprint where the field is used, but I prefer overwriting the files.

1 Like

Should there be a /site/blocks folder that comes with the starterkit? I don’t have one where I could overwrite existing block types. Is there a plugin that I should have added? (I assumed it wasn’t needed with blocks working correctly)

No, you have to create that folder.

You only need a plugin if you want to create Panel previews for blocks.

1 Like

Can you clarify, so we have /site/blocks/ folder to add the yaml and php files to overwrite an existing block. Reading through the docs, it says to add a /site/snippets/blocks/ folder and to then add the blueprint for it in /site/blueprints/blocks/. When do you use which method of overwriting or creating new rules for a custom block?

example: I want to overwrite the existing text block, adding custom html and styles to it. I then made a tipText block within the blueprint. One is an existing block, and one is new. I want to create custom styles and html for both.

Yes, that is correct, sorry, that was a mistake.

Custom block blueprints: /site/blueprints/blocks
Custom block snippets: /site/snippets/blocks

1 Like