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

  • Home
  • SEARCH
  • 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 7537605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:53:46+00:00 2026-05-30T06:53:46+00:00

I have a base Twig template that has a search bar form in it

  • 0

I have a base Twig template that has a search bar form in it at the top of the page in a Twig block. I have another block later on named “content” that my children pages fill out. Currently, my base template looks like this:

{% block admin_bar %}
    <div id="search">
        <form action="{{ path('search') }}" method="post" {{ form_enctype(search_form) }}>
            {{ form_widget(search_form.term) }}
            {{ form_widget(search_form.type) }}
            {{ form_widget(search_form.pool) }}
            {{ form_widget(search_form._token) }}
            <input type="submit" value="Search" />
        </form>
    </div>
{% endblock %}

{% block content %}
{% endblock %}

However, when trying to render a child template I need to pass in the search_form variable along with it. Is there anyway (short of writing out the HTML tags myself) I can avoid having to create this search_form variable and pass it in everytime I want to render a child view? I’m using Twig in conjunction with Symfony2.

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-30T06:53:47+00:00Added an answer on May 30, 2026 at 6:53 am

    Embedded Controller is what you need. Put your admin_bar block into separate file:

    {# src/Acme/AcmeBundle/Resources/views/Search/index.html.twig #}
    <div id="search">
        <form action="{{ path('search') }}" method="post" {{ form_enctype(search_form) }}>
            {{ form_widget(search_form.term) }}
            {{ form_widget(search_form.type) }}
            {{ form_widget(search_form.pool) }}
            {{ form_widget(search_form._token) }}
            <input type="submit" value="Search" />
        </form>
    </div>
    

    Create controller for this template:

    class SearchController extends Controller
    {
        public function indexAction()
        {
            // build the search_form
    
            return $this->render('AcmeAcmeBundle:Search:index.html.twig', array('search_form' => $searchForm));
        }
    }
    

    And then embed controller into your original template:

    {% block admin_bar %}
        {% render "AcmeAcmeBundle:search:index" %}
    {% endblock %}
    
    {% block content %}
    {% endblock %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base page, BasePage, that raises an event that displays messages to
I have a base class that has a private static member: class Base {
I have just created the AcmeHelloBundle so I have this template that has been
I have a base class ActivityA that has some dialogs: public static final int
I have a base class that has an abstract getType() method. I want subclasses
I have a base form that I use when calling 2 forms. Previously when
I have a base class that has a method that creates an instance of
In the project I'm working on now, we have base Entity class that looks
I have a base class that represents a database test in TestNG, and I
I have base 64 encoded string that looks something like this. cuVrcYvlqYze3OZ8Y5tSqQY205mcquu0GsHkgXe4bPg= I have

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.