2

Trying to call a widget (from a custom form extension) in a phtml.

Here's what it looks like when embedded in a CMS page:

{widget type="PluginCompany\ContactForms\Block\Form\Widget\View" form_id="1" show_form_as="form"}

How would I print this in a phtml file, and in such a way that passes those parameters?

3

You must define this class into your block

PluginCompany\ContactForms\Block\Form\Widget\View

So that you can call it from your template.

Then create a function like:

public function getWidgetBlock() {
    return $this->widgetBlock;
}

Where $this->widgetBlock is the variable which will set for widget class in constructor.

Then call this function in phtml, then set those variables like: setFormId(1); and setShowFormAs('form');

After setting these variables you can get widget output by calling function toHtml() from this variable.

For Eg:

$widget = $block->getWidgetBlock(); 
$widget->setFormId(1)->setShowFormAs('form')->toHtml();
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.