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 7159005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:09:33+00:00 2026-05-28T13:09:33+00:00

Is it posible to add custom global templates for items in collection form fields?

  • 0

Is it posible to add custom global templates for items in collection form fields?

I don’t want to customize the collection template itself, but the rendering of each object in the collection, for example for adding a specific class or markup to each object contained in the collection.

I have a form with a collection field added like this:

$builder
    ->add('items', 'collection', array(
        'type' => new ItemType(),
        'allow_add' => true,
        'allow_delete' => true,
        'prototype' => true
    ));

I want to define a twig template to add a “delete” button to each item in the collection (among other things).

I have found there is a ‘collection_widget’ template to customize collections, buy this is only for the collection itself, not individual items.

NOTE 1: I need to use a global template in order to do this for all collections in all forms, I know I can solve this for each form template, but that’s not the point.

NOTE 2: So far I solved this with jquery, adding a class to collection_widget and adding buttons for all it’s children with jquery. This works fine for now, but I’m looking for a 100% template solution, without having to do all the jquery handling. Ideally this should also work with the row prototype for adding new items.

  • 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-28T13:09:34+00:00Added an answer on May 28, 2026 at 1:09 pm

    Finally I found a good solution to this.
    First, I had to create a collection_widget custom template (copied from the generic form_widget) and inside, instead of calling the form_rows block, I call collection_rows block, which is a customization of form_rows block.
    Inside the collection_rows block you can customize whatever you want, I just added a custom class for each child.

    Here’s the two templates:

    {% block collection_widget %}
    {% spaceless %}
        <div {{ block('widget_container_attributes') }}>
            {{ block('collection_rows') }}
            {{ form_rest(form) }}
        </div>
    {% endspaceless %}
    {% endblock collection_widget %}
    
    {% block collection_rows %}
    {% spaceless %}
        {{ form_errors(form) }}
        {% for child in form %}
            {{ form_row(child, {'attr':{'class':'collection-item'}}) }}
        {% endfor %}
    {% endspaceless %}
    {% endblock collection_rows %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to add custom dictionary fields to an images metadata? The following
I use the IE PrintTemplate to add custom page header/footer. The print template sample
Is it possible to add custom fields to drupal navigation menu (besides title and
I want to add custom button on webView. they should also should be there
Is it possible to add include files within my custom t4 templates for the
Is it possible to add different items to a mail item custom context menu
Is it possible to add custom command-line arguments to an Eclipse .app folder? In
is it possible to add custom data to the results so it can be
I was wondering if its possible to add custom header with classic asp. In
Is it possible to add a custom tab to a project properties page in

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.