How to render a form without theme layout
Created 8 years ago by oimkenHere is my plugin, I want it to show a form on a page with specify page type:
Oimken\VotesModule\Vote\Command\RenderVote.php
<?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')
)->render();
}
Oimken\VotesModule\VotesModulePlugin.php
<?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(
'vote',
function ($typeId) {
return $this->dispatch(new RenderVote($typeId));
}
),
];
}
}
...pyrocms/addons/pyro/oimken/votes-module/resources/views/vote.twig
{{ form('vote') }}
......./pyrocms/core/pyrocms/starter-theme/resources/views/layouts/default.twig
<!DOCTYPE html>
<html lang="en">
<head>
{% block metadata deferred %}
{% include "theme::partials/metadata" %}
{% endblock %}
</head>
<body>
{% include "theme::partials/navigation" %}
<div id="content">
{{ vote(1)|raw }} {# type id = 1 #}
</div>
{% include "theme::partials/footer" %}
{% include "theme::partials/scripts" %}
</body>
</html>
In
RenderVote.php
: