How to make editable button texts in forms, which are added as custom blocks?

I created custom block with webform. Client needs several webforms on the same page, all do the same thing - send emails to client. But he needs ability to control what text is on submit button, like “Send inquiry”, “Contact us”.

I tried solution, which comes in mind first: I added field in block, where client can write button text. But getting errors “Can’t use method return value in write context” or “Block error: “Call to a member function name() on null” in block type: “contactform””. Is there any way to do this?

Please post the code that is causes the errors

Structure is this:


<?php snippet('contact-form') ?>

and /snippets/contact-form.php

<form class="registration-form" action="<?= $page->url() ?>" method="POST">

<?php $block->name() = $name ?>

Last line causes this error.

And this <?= $block->name() ?> causes another error, however this code works, if it’s in /snippets/blocks/contactform.php

This code is an assignment, you probably want to compare something here using == or ===.

We can ignore this part, sorry, just wanted to assign variable, but mixed positions.

The problem is it’s impossible to print fields from block like <?= $block->name() ?> in form file.

If you want to pass variables to a snippet that is included in your block snippet, then you have to pass those variables down, like you do in other contexts:

snippet('some-snippet', [ /*array of variables*/ ])

Great, clear now, made it work, thanks a lot!