Symfony4 Twig template error: Variable “widget” does not exist












0















I am getting Twig_Error_Runtime
enter image description here



I am trying to find the mistake I've made, but I can't see any... maybe I am looking at the wrong file, but I've tried looking everywhere I've done changes before this error appeared.



This is my twig code:



{% extends 'base.html.twig' %}
{% block body %}
<div class="container">

{% form_theme form 'bootstrap_4_layout.html.twig' %}
{{ form_start(form) }}

<br>

Name {{ form_widget(form.name) }}
Price {{ form_widget(form.price) }}
Available {{ form_widget(form.available) }}
Date {{ form_widget(form.date) }}
<div class="row js-ticket-time-wrapper"
data-prototype="{{ form_widget(form.times.vars.prototype)|e('html_attr') }}"
data-index="{{ form.times|length }}">
{% for time in form.times %}
<div class="col-xs-4 js-ticket-time-item">
<a href="#" class="js-remove-time pull-right">
<span class="fa fa-close"></span>
</a>
{{ form_row(time.name) }}
</div>
{% endfor %}
<a href="#" class="js-ticket-time-add">
<span class="fa fa-plus-circle"></span>
Add another Time
</a>
</div>
<button type="submit" class="btn btn-primary" formnovalidate>Save</button>
{{ form_end(form) }}
</div>

{% endblock %}
{% block js %}
{{ parent() }}
<script>
jQuery(document).ready(function() {
var $wrapper = $('.js-ticket-time-wrapper');
$wrapper.on('click', '.js-remove-time', function(e) {
e.preventDefault();
$(this).closest('.js-ticket-time-item')
.fadeOut()
.remove();
});
$wrapper.on('click', '.js-ticket-time-add', function(e) {
e.preventDefault();
// Get the data-prototype explained earlier
var prototype = $wrapper.data('prototype');
// get the new index
var index = $wrapper.data('index');
// Replace '__name__' in the prototype's HTML to
// instead be a number based on how many items we have
var newForm = prototype.replace(/__name__/g, index);
// increase the index with one for the next item
$wrapper.data('index', index + 1);
// Display the form in the page before the "new" link
$(this).before(newForm);
});
});
</script>
{% endblock %}


I've also made changes in Entities Time & Ticket, but I don't think so this is connected somehow.



Here's my TicketType Form:



public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name',TextType::class)
->add('price',MoneyType::class)
->add('available',IntegerType::class)
->add('date',DateType::class)
->add('times', CollectionType::class, array(
'entry_type' => AppFormTimeType::class,
'allow_delete' => true,
'by_reference' => false,
'allow_add' => true,
));
}


And this is TimeType:



public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', TextType::class);
}









share|improve this question























  • Why not 'entry_type' => TextType::class, directly? note that TimeType will use block time_widget by default which is a built-in type. By changing the name of the type MyTimeType or overriding the block name should fix the issue.

    – yceruto
    Nov 20 '18 at 13:02
















0















I am getting Twig_Error_Runtime
enter image description here



I am trying to find the mistake I've made, but I can't see any... maybe I am looking at the wrong file, but I've tried looking everywhere I've done changes before this error appeared.



This is my twig code:



{% extends 'base.html.twig' %}
{% block body %}
<div class="container">

{% form_theme form 'bootstrap_4_layout.html.twig' %}
{{ form_start(form) }}

<br>

Name {{ form_widget(form.name) }}
Price {{ form_widget(form.price) }}
Available {{ form_widget(form.available) }}
Date {{ form_widget(form.date) }}
<div class="row js-ticket-time-wrapper"
data-prototype="{{ form_widget(form.times.vars.prototype)|e('html_attr') }}"
data-index="{{ form.times|length }}">
{% for time in form.times %}
<div class="col-xs-4 js-ticket-time-item">
<a href="#" class="js-remove-time pull-right">
<span class="fa fa-close"></span>
</a>
{{ form_row(time.name) }}
</div>
{% endfor %}
<a href="#" class="js-ticket-time-add">
<span class="fa fa-plus-circle"></span>
Add another Time
</a>
</div>
<button type="submit" class="btn btn-primary" formnovalidate>Save</button>
{{ form_end(form) }}
</div>

{% endblock %}
{% block js %}
{{ parent() }}
<script>
jQuery(document).ready(function() {
var $wrapper = $('.js-ticket-time-wrapper');
$wrapper.on('click', '.js-remove-time', function(e) {
e.preventDefault();
$(this).closest('.js-ticket-time-item')
.fadeOut()
.remove();
});
$wrapper.on('click', '.js-ticket-time-add', function(e) {
e.preventDefault();
// Get the data-prototype explained earlier
var prototype = $wrapper.data('prototype');
// get the new index
var index = $wrapper.data('index');
// Replace '__name__' in the prototype's HTML to
// instead be a number based on how many items we have
var newForm = prototype.replace(/__name__/g, index);
// increase the index with one for the next item
$wrapper.data('index', index + 1);
// Display the form in the page before the "new" link
$(this).before(newForm);
});
});
</script>
{% endblock %}


I've also made changes in Entities Time & Ticket, but I don't think so this is connected somehow.



Here's my TicketType Form:



public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name',TextType::class)
->add('price',MoneyType::class)
->add('available',IntegerType::class)
->add('date',DateType::class)
->add('times', CollectionType::class, array(
'entry_type' => AppFormTimeType::class,
'allow_delete' => true,
'by_reference' => false,
'allow_add' => true,
));
}


And this is TimeType:



public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', TextType::class);
}









share|improve this question























  • Why not 'entry_type' => TextType::class, directly? note that TimeType will use block time_widget by default which is a built-in type. By changing the name of the type MyTimeType or overriding the block name should fix the issue.

    – yceruto
    Nov 20 '18 at 13:02














0












0








0








I am getting Twig_Error_Runtime
enter image description here



I am trying to find the mistake I've made, but I can't see any... maybe I am looking at the wrong file, but I've tried looking everywhere I've done changes before this error appeared.



This is my twig code:



{% extends 'base.html.twig' %}
{% block body %}
<div class="container">

{% form_theme form 'bootstrap_4_layout.html.twig' %}
{{ form_start(form) }}

<br>

Name {{ form_widget(form.name) }}
Price {{ form_widget(form.price) }}
Available {{ form_widget(form.available) }}
Date {{ form_widget(form.date) }}
<div class="row js-ticket-time-wrapper"
data-prototype="{{ form_widget(form.times.vars.prototype)|e('html_attr') }}"
data-index="{{ form.times|length }}">
{% for time in form.times %}
<div class="col-xs-4 js-ticket-time-item">
<a href="#" class="js-remove-time pull-right">
<span class="fa fa-close"></span>
</a>
{{ form_row(time.name) }}
</div>
{% endfor %}
<a href="#" class="js-ticket-time-add">
<span class="fa fa-plus-circle"></span>
Add another Time
</a>
</div>
<button type="submit" class="btn btn-primary" formnovalidate>Save</button>
{{ form_end(form) }}
</div>

{% endblock %}
{% block js %}
{{ parent() }}
<script>
jQuery(document).ready(function() {
var $wrapper = $('.js-ticket-time-wrapper');
$wrapper.on('click', '.js-remove-time', function(e) {
e.preventDefault();
$(this).closest('.js-ticket-time-item')
.fadeOut()
.remove();
});
$wrapper.on('click', '.js-ticket-time-add', function(e) {
e.preventDefault();
// Get the data-prototype explained earlier
var prototype = $wrapper.data('prototype');
// get the new index
var index = $wrapper.data('index');
// Replace '__name__' in the prototype's HTML to
// instead be a number based on how many items we have
var newForm = prototype.replace(/__name__/g, index);
// increase the index with one for the next item
$wrapper.data('index', index + 1);
// Display the form in the page before the "new" link
$(this).before(newForm);
});
});
</script>
{% endblock %}


I've also made changes in Entities Time & Ticket, but I don't think so this is connected somehow.



Here's my TicketType Form:



public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name',TextType::class)
->add('price',MoneyType::class)
->add('available',IntegerType::class)
->add('date',DateType::class)
->add('times', CollectionType::class, array(
'entry_type' => AppFormTimeType::class,
'allow_delete' => true,
'by_reference' => false,
'allow_add' => true,
));
}


And this is TimeType:



public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', TextType::class);
}









share|improve this question














I am getting Twig_Error_Runtime
enter image description here



I am trying to find the mistake I've made, but I can't see any... maybe I am looking at the wrong file, but I've tried looking everywhere I've done changes before this error appeared.



This is my twig code:



{% extends 'base.html.twig' %}
{% block body %}
<div class="container">

{% form_theme form 'bootstrap_4_layout.html.twig' %}
{{ form_start(form) }}

<br>

Name {{ form_widget(form.name) }}
Price {{ form_widget(form.price) }}
Available {{ form_widget(form.available) }}
Date {{ form_widget(form.date) }}
<div class="row js-ticket-time-wrapper"
data-prototype="{{ form_widget(form.times.vars.prototype)|e('html_attr') }}"
data-index="{{ form.times|length }}">
{% for time in form.times %}
<div class="col-xs-4 js-ticket-time-item">
<a href="#" class="js-remove-time pull-right">
<span class="fa fa-close"></span>
</a>
{{ form_row(time.name) }}
</div>
{% endfor %}
<a href="#" class="js-ticket-time-add">
<span class="fa fa-plus-circle"></span>
Add another Time
</a>
</div>
<button type="submit" class="btn btn-primary" formnovalidate>Save</button>
{{ form_end(form) }}
</div>

{% endblock %}
{% block js %}
{{ parent() }}
<script>
jQuery(document).ready(function() {
var $wrapper = $('.js-ticket-time-wrapper');
$wrapper.on('click', '.js-remove-time', function(e) {
e.preventDefault();
$(this).closest('.js-ticket-time-item')
.fadeOut()
.remove();
});
$wrapper.on('click', '.js-ticket-time-add', function(e) {
e.preventDefault();
// Get the data-prototype explained earlier
var prototype = $wrapper.data('prototype');
// get the new index
var index = $wrapper.data('index');
// Replace '__name__' in the prototype's HTML to
// instead be a number based on how many items we have
var newForm = prototype.replace(/__name__/g, index);
// increase the index with one for the next item
$wrapper.data('index', index + 1);
// Display the form in the page before the "new" link
$(this).before(newForm);
});
});
</script>
{% endblock %}


I've also made changes in Entities Time & Ticket, but I don't think so this is connected somehow.



Here's my TicketType Form:



public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name',TextType::class)
->add('price',MoneyType::class)
->add('available',IntegerType::class)
->add('date',DateType::class)
->add('times', CollectionType::class, array(
'entry_type' => AppFormTimeType::class,
'allow_delete' => true,
'by_reference' => false,
'allow_add' => true,
));
}


And this is TimeType:



public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', TextType::class);
}






symfony twig






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 11:45









phamephame

406




406













  • Why not 'entry_type' => TextType::class, directly? note that TimeType will use block time_widget by default which is a built-in type. By changing the name of the type MyTimeType or overriding the block name should fix the issue.

    – yceruto
    Nov 20 '18 at 13:02



















  • Why not 'entry_type' => TextType::class, directly? note that TimeType will use block time_widget by default which is a built-in type. By changing the name of the type MyTimeType or overriding the block name should fix the issue.

    – yceruto
    Nov 20 '18 at 13:02

















Why not 'entry_type' => TextType::class, directly? note that TimeType will use block time_widget by default which is a built-in type. By changing the name of the type MyTimeType or overriding the block name should fix the issue.

– yceruto
Nov 20 '18 at 13:02





Why not 'entry_type' => TextType::class, directly? note that TimeType will use block time_widget by default which is a built-in type. By changing the name of the type MyTimeType or overriding the block name should fix the issue.

– yceruto
Nov 20 '18 at 13:02












1 Answer
1






active

oldest

votes


















1














Because the classname of your formtype TimeType is the same as the Symfony TimeType (https://symfony.com/doc/current/reference/forms/types/time.html) the formtheme layout tries to render the symfony type instead of yours. You can see the symfony TimeType has an option called widget so the formtype is expecting this type.



So try to rename your TimeType to something else like TicketTimeType.



Or you can rename your block prefix like this in your TimeType:



public function getBlockPrefix()
{
return "ticket_time_type";
}





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53392329%2fsymfony4-twig-template-error-variable-widget-does-not-exist%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Because the classname of your formtype TimeType is the same as the Symfony TimeType (https://symfony.com/doc/current/reference/forms/types/time.html) the formtheme layout tries to render the symfony type instead of yours. You can see the symfony TimeType has an option called widget so the formtype is expecting this type.



    So try to rename your TimeType to something else like TicketTimeType.



    Or you can rename your block prefix like this in your TimeType:



    public function getBlockPrefix()
    {
    return "ticket_time_type";
    }





    share|improve this answer






























      1














      Because the classname of your formtype TimeType is the same as the Symfony TimeType (https://symfony.com/doc/current/reference/forms/types/time.html) the formtheme layout tries to render the symfony type instead of yours. You can see the symfony TimeType has an option called widget so the formtype is expecting this type.



      So try to rename your TimeType to something else like TicketTimeType.



      Or you can rename your block prefix like this in your TimeType:



      public function getBlockPrefix()
      {
      return "ticket_time_type";
      }





      share|improve this answer




























        1












        1








        1







        Because the classname of your formtype TimeType is the same as the Symfony TimeType (https://symfony.com/doc/current/reference/forms/types/time.html) the formtheme layout tries to render the symfony type instead of yours. You can see the symfony TimeType has an option called widget so the formtype is expecting this type.



        So try to rename your TimeType to something else like TicketTimeType.



        Or you can rename your block prefix like this in your TimeType:



        public function getBlockPrefix()
        {
        return "ticket_time_type";
        }





        share|improve this answer















        Because the classname of your formtype TimeType is the same as the Symfony TimeType (https://symfony.com/doc/current/reference/forms/types/time.html) the formtheme layout tries to render the symfony type instead of yours. You can see the symfony TimeType has an option called widget so the formtype is expecting this type.



        So try to rename your TimeType to something else like TicketTimeType.



        Or you can rename your block prefix like this in your TimeType:



        public function getBlockPrefix()
        {
        return "ticket_time_type";
        }






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 20 '18 at 13:07

























        answered Nov 20 '18 at 12:52









        FabianFabian

        6001721




        6001721






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53392329%2fsymfony4-twig-template-error-variable-widget-does-not-exist%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            Npm cannot find a required file even through it is in the searched directory