Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6907553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:26:58+00:00 2026-05-27T08:26:58+00:00

I am trying to alter the date_widget using symfony2 and twig. I would like

  • 0

I am trying to alter the date_widget using symfony2 and twig. I would like to display just the year.

After reading Symfony 2 date input with only year selector and the symfony2 book chapter on templating forms I have copied the date_widget block into my template and am receiving the error:

Variable “widget” does not exist in bundle….

here is the code from my template:

{% extends '::base.html.twig' %}
{% block body %}

{% block date_widget %}
{% spaceless %}
    {% if widget == 'single_text' %}
         {{ block('field_widget') }}
    {% else %}
        <div {{ block('widget_container_attributes') }}>
            {{ date_pattern|replace({
                '{{ year }}': form_widget(form.year),
            })|raw }}
        </div>
    {% endif %}
{% endspaceless %}
{% endblock date_widget %}

....print form (generated though app/console generate:crud)

{% endblock %}

Any Thoughts? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:26:58+00:00Added an answer on May 27, 2026 at 8:26 am

    put the date_widget block outside of the body block, and add the following code after the initial extends

    {% form_theme form _self %}
    

    now, your code should look like this

    {% extends '::base.html.twig' %}
    {% form_theme form _self %}
    
    {% block body %}
    
    ....print form (generated though app/console generate:crud)
    
    {% endblock %}
    
    {% block date_widget %}
    {% spaceless %}
        {% if widget == 'single_text' %}
             {{ block('field_widget') }}
        {% else %}
            <div {{ block('widget_container_attributes') }}>
                {{ date_pattern|replace({
                    '{{ year }}': form_widget(form.year),
                })|raw }}
            </div>
        {% endif %}
    {% endspaceless %}
    {% endblock date_widget %}
    

    http://symfony.com/doc/current/book/forms.html#form-theming

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to alter how a combobox is displayed using the following code: private
After trying to avoid JavaScript for years, Iv started using Query for validation in
I'm trying to implement a iGoogle like dashboard interface using widgets that get their
I am trying to send an ajax request immediately after a date is chosen
I've been trying to avoid using a cursor in this particular case just because
Trying to display my custom post types for specific date ranges. I want to
I am trying to create a persisted computed column using CASE expression: ALTER TABLE
We've been trying to alter a lot of columns from nullable to not nullable,
I'm trying to ALTER a table by adding a new CLOB column (on Oracle
I'm trying to use the IE specific conditional statements to alter class settings based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.