Bonjour,

Je souhaite donner des placeholder différents pour un même champs de texte qui apparait sur différents formulaire dans la même page :

Nom : Capture.PNG
Affichages : 914
Taille : 58,0 Ko

Ma vue en Twig :

_ad.html.twig

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<div class="field">
    <div>{{ form_widget(ad.brand) }}</div>
 
    {{ form_errors(ad.brand) }}
</div>
<div class="field">
    <div class="custom-select">{{ form_widget(ad.model) }}</div>
    {{ form_errors(ad.model) }}
</div>
{% if ad.price is defined %}
    <div class="field ad-price cf">
        {{ form_widget(ad.price, {'attr' : {'placeholder': placeholder|default('crm.ad.price')} }) }}
        {{ form_errors(ad.price) }}
    </div>
{% endif %}
<div class="field ad-km cf">
    {{ form_widget(ad.kilometers) }}
    {{ form_errors(ad.kilometers) }}
</div>
<div class="field ad-license cf">
    {{ form_widget(ad.licensePlate) }}
    {{ form_errors(ad.licensePlate) }}
</div>
<div class="field ad-fuel">
    <div class="custom-select">{{ form_widget(ad.fuel) }}</div>
    {{ form_errors(ad.fuel) }}
</div>
<div class="field ad-gearbox">
    <div class="custom-select">{{ form_widget(ad.gearbox) }}</div>
    {{ form_errors(ad.gearbox) }}
</div>
<div class="field ad-reference">
    {{ form_widget(ad.reference) }}
    {{ form_errors(ad.reference) }}
</div>
<div class="field ads-links">
    {{ form_widget(ad.link) }}
    {{ form_errors(ad.link) }}
</div>
 
{% if pvo is defined %}
    <!-- a href="#" class="searchPvo button icon-search"> Rechercher</a>
    <div class="field pvo">
        <div class="custom-select" {% if ad.vehiculePvo is null %}style="display:none" {% endif %}>{{ form_widget(ad.vehiculePvo) }}</div>
        {{ form_errors(ad.vehiculePvo) }}
    </div -->
{% endif %}
 
{% if ad.vars.value is not null and ad.vars.value.link != '' %}
    <a href="{{ ad.vars.value.link }}" target="_blank" class="link">{{ ad.vars.value.link }}</a>
{% endif %}
Le formulaire plus haut est appelé plusieurs fois dans une autre vue Twig, pour chaque univers, j'ai une div qui englobe ceci :

_form.html.twig
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
        <!--div id="universAtelierEtAutre" -->
            <div id="universAtelier" class="univers" {% if lead.interest is not null and lead.interest.code != 'atelier' %}style="display: none"{% endif %}>
                <h4><span class="custom-radio interest-id">{{ form_widget( form.interest[40], {'attr' : {'class' : 'radio-univers'}} ) }}<label for="{{ formName|default('lead') }}_interest_40">{{ 'crm.menu.repair'|trans }}</label></span></h4>
                <div class="fields">
 
                    <div class="field">
                        <div class="custom-select">{{ form_widget(form.AtelierLead.atelierType) }}</div>
                        {{ form_errors(form.AtelierLead.atelierType) }}
                    </div>
                    <div id="adsList2" class="collection-list cf workshop">
                        <div class="ads cf" data-prototype="{% filter escape %}{% include 'CarvivoCrmBundle:Ad:_ad.html.twig' with {'ad': form.AtelierLead.ads.vars.prototype} %}{% endfilter %}">
                            {% for ad in form.AtelierLead.ads %}
                                <div class="collection-item ad cf">{% include 'CarvivoCrmBundle:Ad:_ad.html.twig' with {'ad': ad} %}</div>
                            {% endfor %}
                            <div style="display:none">{{ form_row(form.AtelierLead.ads) }}</div>
                        </div>
                    </div>
                </div>
                <div class="fields">
 
                    <div class="field">
                        <div class="custom-select">{{ form_widget(form.AtelierLead.appointmentType) }}</div>
                        {{ form_errors(form.AtelierLead.appointmentType) }}
                    </div>
 
                    <div class="field checkbox">
                        {{ form_widget(form.AtelierLead.urgent) }}
                        {{ form_label(form.AtelierLead.urgent) }}
                        {{ form_errors(form.AtelierLead.urgent) }}
                    </div>
 
                    <div id="datesList" class="collection-list cf">
                        <div class="dates cf" data-prototype="{% filter escape %}{% include 'CarvivoCrmBundle:Operator/Lead:_appointmentDate.html.twig' with {'appointmentDate': form.AtelierLead.appointmentDates.vars.prototype} %}{% endfilter %}">
                            {% for appointmentDate in form.AtelierLead.appointmentDates %}
                                <div class="collection-item appointment-date cf">{% include 'CarvivoCrmBundle:Operator/Lead:_appointmentDate.html.twig' with {'appointmentDate': appointmentDate} %}</div>
                            {% endfor %}
                            <div style="display:none">{{ form_row(form.AtelierLead.appointmentDates) }}</div>
                        </div>
                    </div>
 
                </div>
            </div>
J'ai beau mettre des conditions dans mon fichier _ad.html.twig pour le champ que je veux changer :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
<div class="field ad-reference">
    {{ form_widget(ad.reference) }}
    {{ form_errors(ad.reference) }}
</div>
Rien y fait, le placeholder se modifie pour tous mes champs.