twig

Is there a Twig shorthand syntax for outputting conditional text

♀尐吖头ヾ 提交于 2021-01-20 15:43:27
问题 Is there a shorter syntax in Twig to output a conditional string of text? <h1>{% if not info.id %}create{% else %}edit{% endif %}</h1> Traditional php is even easier than this: <h1><?php info['id']? 'create' : 'edit' ?></h1> 回答1: This should work: {{ not info.id ? 'create' : 'edit' }} Also, this is called the ternary operator. It's kind of hidden in the documenation: twig docs: operators From their documentation the basic structure is: {{ foo ? 'yes' : 'no' }} 回答2: If you need to compare the

Is there a Twig shorthand syntax for outputting conditional text

一曲冷凌霜 提交于 2021-01-20 15:43:11
问题 Is there a shorter syntax in Twig to output a conditional string of text? <h1>{% if not info.id %}create{% else %}edit{% endif %}</h1> Traditional php is even easier than this: <h1><?php info['id']? 'create' : 'edit' ?></h1> 回答1: This should work: {{ not info.id ? 'create' : 'edit' }} Also, this is called the ternary operator. It's kind of hidden in the documenation: twig docs: operators From their documentation the basic structure is: {{ foo ? 'yes' : 'no' }} 回答2: If you need to compare the

Disable VS Code javascript check

主宰稳场 提交于 2021-01-07 06:04:33
问题 I am passing a twig object to javascript via script tags in a .html.twig file, and VS Code complains that "Property assignment expected. js [17, 38]". Is it possible to turn this off completely for .html.twig-files or perhaps turn off checking altogether? I am using ESLint extension in any case. <script> ... window.PROPS = {{ props|json_encode|raw }}; ... </script> (edit) Just to clarify, ESLint is not responsible for these problem-messages. I can turn off the ESLint extension (and reload the

Disable VS Code javascript check

a 夏天 提交于 2021-01-07 06:02:30
问题 I am passing a twig object to javascript via script tags in a .html.twig file, and VS Code complains that "Property assignment expected. js [17, 38]". Is it possible to turn this off completely for .html.twig-files or perhaps turn off checking altogether? I am using ESLint extension in any case. <script> ... window.PROPS = {{ props|json_encode|raw }}; ... </script> (edit) Just to clarify, ESLint is not responsible for these problem-messages. I can turn off the ESLint extension (and reload the

How to add multiple ID on an element in Twig

谁说胖子不能爱 提交于 2021-01-07 02:24:27
问题 I need to add 2 different ID from 2 different table in my database (to get all informations about each id ) in my URL. I got this exception: Neither the property "car" nor one of the methods "car()", "getcar()"/"iscar()"/"hascar()" or "__call()" exist and have public access in class "App\Entity\Quote". I'm not good with CustomRepository so I am wondering if there is an other way. This is my controller: /** * @Route("/individualQuote/{id}", name="user_individualQuote", methods={"GET","POST"})

How to add multiple ID on an element in Twig

本小妞迷上赌 提交于 2021-01-07 02:21:48
问题 I need to add 2 different ID from 2 different table in my database (to get all informations about each id ) in my URL. I got this exception: Neither the property "car" nor one of the methods "car()", "getcar()"/"iscar()"/"hascar()" or "__call()" exist and have public access in class "App\Entity\Quote". I'm not good with CustomRepository so I am wondering if there is an other way. This is my controller: /** * @Route("/individualQuote/{id}", name="user_individualQuote", methods={"GET","POST"})

Shopware 6 | Cloning CmsElement and get null as data

我是研究僧i 提交于 2020-12-06 07:04:33
问题 I try to clone the content element image-slider or image-gallery (the error will come at both) to extend them. First I register a new CmsElement like the original only changes the name from image-slider to image-slider-example import './component'; import './config'; import './preview'; Shopware.Service('cmsService').registerCmsElement({ name: 'image-slider-example', label: 'sw-cms.elements.imageSlider.label', component: 'sw-cms-el-image-slider', configComponent: 'sw-cms-el-config-image

Twig: How to get the first character in a string

筅森魡賤 提交于 2020-12-04 15:58:04
问题 I am implementing an alphabetical search. We display a table of Names. I want to highlight only those alphabets, which have names that begin with the corresponding alphabet. I am stumped with a simple problem. How to read the first character in the string user.name within twig. I have tried several strategies, including the [0] operation but it throws an exception. Here is the code {% for i in ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y'

Symfony - Add text in generated form

不羁的心 提交于 2020-12-03 17:58:52
问题 I'd like to do something quite simple, but I can't figure out how to manage it. I have a form: {{ form_start(form) }} {{ form_widget(form) }} {{ form_end(form) }} There are several text field in it. I'd like to "insert" some text (like <p>my Text</p> ) between two text fields (let's say between name text field and description text field). Form are generated with form builder tool. I've tried something like: $builder ->add('stuffName') // works well (text field 1) ->add('addedText', 'text',

Multidimensional Array in Twig

走远了吗. 提交于 2020-12-01 12:10:37
问题 I am using Twig with PHP. I have a multidimensional array setup like this: Array ( [Special] => Array ( [277] => Array ( [name] => First Item [quantity] => 1 [price] => 0 ) [276] => Array ( [name] => Second Item [quantity] => 11 [price] => 0 ) [278] => Array ( [name] => Third Item [quantity] => 2 [price] => 0 ) ) [Technical] => Array ( [14] => Array ( [name] => First Item [quantity] => 1 [price] => 1 ) ) [Books] => Array ( [169] => Array ( [name] => First Item [quantity] => 2 [price] => 100 )