Skip to content

Added custom HTML block for raw HTML or view insertions into form.#5

Merged
gtrinkwon merged 2 commits intomainfrom
feature/custom-html-block
Apr 10, 2026
Merged

Added custom HTML block for raw HTML or view insertions into form.#5
gtrinkwon merged 2 commits intomainfrom
feature/custom-html-block

Conversation

@gtrinkwon
Copy link
Copy Markdown
Member

Called in the form builder like so:

            ->add('custom_block', CustomHtmlBlockType::class, [
                'html' => '',
                'view' => view('path.to.template', [
                    'my_twig_variable' => 'foobar'
                ])
            ])

@gtrinkwon gtrinkwon requested a review from simonrjones March 18, 2026 10:42

{# Custom HTML block #}
{%- block custom_html_block_row -%}
{%- if html is not empty -%}{{ html }}{%- endif -%}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to test this do you? I thought Twig auto detected if variables are set and returns null if not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it returns null unless strict_variables = true.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's been updated to remove the conditional now.

use Symfony\Component\OptionsResolver\OptionsResolver;
use Twig\Markup;

class CustomHtmlBlockType extends AbstractType
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename to Html to make this easier to use? E.g.

>add('custom_block', Html::class, [
                'view' => view('path.to.template', [
                    'my_twig_variable' => 'foobar'
                ])
            ])

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, CustomHtmlBlockType has been renamed To Html. Just changes the usage and the twig template row block name (now html_row).

@gtrinkwon gtrinkwon marked this pull request as ready for review April 10, 2026 15:21
@gtrinkwon gtrinkwon merged commit 459050e into main Apr 10, 2026
0 of 3 checks passed
@gtrinkwon gtrinkwon deleted the feature/custom-html-block branch April 10, 2026 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants