为symfony2 twig表单添加内联样式

时间:2016-09-01 09:56:49

标签: css twig symfony-forms

{{ form_widget(titleForm.titleBasic, {'attr' : {'style' : { 'color:red', 'border:none' } }} ) }}

有时候我使用了内联css,但我忘了如何为内联css编写twig sintax。

3 个答案:

答案 0 :(得分:0)

感谢Matteo我们找到了解决方案。

{{ form_widget(titleForm.titleBasic, {'attr' : {'style' : 'color:red, border:none' } }} ) }}

答案 1 :(得分:0)

这对我有用。使用; 代替

static void Main(string[] args)
    {

        var types = new[] { typeof(ExampleClass), typeof(ExampleClass[]) };
        var objects = new List<object>();

        foreach (var type in types)
        {
            var typeInstance = type.GetElementType();

            if (typeInstance != null)
            {
                Debug.WriteLine($"{typeInstance}");
                objects.Add(Activator.CreateInstance(typeInstance));
            }
            else
            {
                objects.Add(Activator.CreateInstance(type));
            }
        }
    }

   public class ExampleClass
   {
        public int X;
        public int Y;
   }

答案 2 :(得分:0)

即使这是一个古老但仍然正确的答案,我还是偶然发现了它。更好,更干净的方法是将样式设置为FormType:

        ->add('foo', TextType::class, [
        'attr' => [
            'style' => 'color:red, border:none',
            'placeholder' => 'Foo'
          ]
        ])

通过这种方式,如果您在其他模板中使用该表单,则在呈现它时不必编写额外的内联CSS。