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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:51:36+00:00 2026-06-06T06:51:36+00:00

I have some *Type form classes and a forms.html.twig to customize form appearance. By

  • 0

I have some *Type form classes and a forms.html.twig to customize form appearance. By default, in this file the labels are rendered with this block:

<label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>{{ label|trans }}</label>

I’d like to add a prefix to the label ir order to organize my translations. For example let’s say I have a CustomerType, then I’d like my labels to be like:

<label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>
  {{ 'Customer.' ~ label|trans }}
</label>

I want to be able to pass that 'Customer' string to the FormBuilder in such a way that I am able to use it like:

<label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>
  {{ prefix ~ '.' ~ label|trans }}
</label>

or maybe:

<label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>
  {{ form.prefix ~ '.' ~ label|trans }
}</label>

Does someone know how to achieve this?

  • 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-06-06T06:51:37+00:00Added an answer on June 6, 2026 at 6:51 am

    With Symfony 2.1

    <?php
    namespace MyProject\MyBundle\Form\Extension;
    
    use Symfony\Component\Form\AbstractTypeExtension;
    use Symfony\Component\Form\FormBuilder;
    use Symfony\Component\Form\FormView;
    use Symfony\Component\Form\FormInterface;
    
    class FieldTypeExtendedExtension extends AbstractTypeExtension
    {
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            $builder->setAttribute('label_prefix', $options['label_prefix']);
        }
    
        public function buildView(FormViewInterface $view, FormInterface $form, array $options)
        {
            $labelPrefix = $form->getRoot()->hasAttribute('label_prefix') ? $form->getRoot()->getAttribute('label_prefix') : '';
            $view->setVar('label', $labelPrefix.$view->getVar('label'));
        }
    
        public function setDefaultOptions(OptionsResolverInterface $resolver)
        {
            $resolver->setDefaults(array(
                'label_prefix' => ''
            ));
        }
    
        public function getExtendedType()
        {
            return 'form';
        }
    }
    

    Declare this extension as a service

    <service id="form.type_extension.fieldextended" class="MyProject\MyBundle\Form\Extension\FieldTypeExtendedExtension">
        <tag name="form.type_extension" alias="form" />
    </service>
    

    For more informations, see the documentation.

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

Sidebar

Related Questions

I've some classes defined in a dll file. These are in the form of
Does .NET have some type of built in function that allows filtering on Gridviews?
I have some custom type: [RdfSerializable] public class Item { [RdfProperty(true)] public string Name
I have some logic in a method that operates on a specified type and
I have some security related service running on my machine (start type = automatic)
I have some specific id like 1,2,5,11,64589 in solr (int type) I want to
Suppose I have some class which has a property actor_ of type Actor .
I recently asked this question about how to simulate type classes in D and
Hi i'm working in a class library using C#, and i have some classes
I have a simple form, then I placed some data from the table to

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.