How to render a form without theme layout

oimken - 3 months ago

Here is my plugin, I want it to show a form on a page with specify page type:


<?php namespace Oimken\VotesModule\Vote\Command;

use Illuminate\View\Factory;
use Oimken\VotesModule\Vote\Form\Command\AddFrontFormFromTypeId;
use Oimken\VotesModule\Vote\Form\VoteEntryFormBuilder;
use Oimken\VotesModule\Vote\Form\VoteFrontFormBuilder;
use Illuminate\Foundation\Bus\DispatchesJobs;

class RenderVote

    use DispatchesJobs;

    protected $typeId;

    public function __construct($typeId)
        $this->typeId = $typeId;

    public function handle(VoteEntryFormBuilder $form, Factory $view)

        $this->dispatch(new AddFrontFormFromTypeId($form, $this->typeId));

        return  $form->render(); // This works, render the form with theme's layout

// try to render the form content only, without the layout...   failure.
       return $view->make(
            $options->get('view', 'oimken.module.votes::vote'),
//            compact('votes', 'options')


<?php namespace Oimken\VotesModule;

use Anomaly\Streams\Platform\Addon\Plugin\Plugin;
use Oimken\VotesModule\Vote\Command\RenderVote;

class VotesModulePlugin extends Plugin

     * Get the plugin functions.
     * @return array
    public function getFunctions()
        return [
            new \Twig_SimpleFunction(
                function ($typeId) {
                    return $this->dispatch(new RenderVote($typeId));


{{ form('vote') }}


<!DOCTYPE html>
<html lang="en">

    {% block metadata deferred %}
    {% include "theme::partials/metadata" %}
    {% endblock %}


{% include "theme::partials/navigation" %}

<div id="content">
{{ vote(1)|raw }} {# type id = 1 #}

{% include "theme::partials/footer" %}
{% include "theme::partials/scripts" %}



I almost exhaustion to deal with this, Please help me , many many thanks.

daviesgeek - 3 months ago

In RenderVote.php:

return $form->make()->getFormContent();

keevitaja - 3 months ago

@oimken in similar situations sometimes you can cast presentable object to string just by casting it with (string) $object

this works when object has __toString() magic method attached to it

oimken - 3 months ago

OMG ! That's Sweet! It works!

but missing the form's sections VoteEntryFormSections