twig

Opencart 3.x category id in product page

a 夏天 提交于 2020-01-24 01:57:06
问题 I'm using opencart 3.0.2.0 I'm trying to get category id in the product page. Any suggestions ? 回答1: If you just want to get category id in the product page Open product.php file from catalog/controller/product and search for $product_info = $this->model_catalog_product->getProduct($product_id); replace it with $product_info = $this->model_catalog_product->getProduct($product_id); $query_categories = $this->model_catalog_product->getCategories($product_id); $categories = array(); foreach (

Having more than one controller in one view in Symfony?

孤街醉人 提交于 2020-01-24 00:23:08
问题 Can someone explain to me about this? can we have more than one controller in one view (html.twig) in Symfony? If it can using multiple controller in a view, how to use it? Can give me an example how to 回答1: I'm guessing you want to use render. Here's the documentation & example: http://symfony.com/doc/current/book/templating.html#embedding-controllers 来源: https://stackoverflow.com/questions/27810785/having-more-than-one-controller-in-one-view-in-symfony

Twig: how to check the inner html content of a field

假装没事ソ 提交于 2020-01-23 12:25:32
问题 i have a single field and that field can have one or two lines of html: <p>One line</p> or: <p>first line</p> <p>Second line </p> Using twig how can i check if the field has one or two tags. Example of what i want to do: {% if item|length('<p>') = 1 %} <div class="one">{{ item }}</div> {% elseif item|length('<p>') = 2 %} <div class="two">{{ item }}</div> {% endif %} Any ideas of how to accomplish this? Update #1: What Honza said is true I want the parent div to have a class if there is only

Symfony 4 - Not rendering Twig Template

牧云@^-^@ 提交于 2020-01-23 08:56:47
问题 When trying to render a Twig Template within a Symfony 4 project I'm getting an error. I don't know which is the problem. This is the code generating the error: return $this->render('templates/imagenes/index.html.twig'); And this is the error I'm getting: LogicException You can not use the "render" method if the Templating Component or the Twig Bundle are not available. Should I install Twig via composer apart Symfony itself? 回答1: Thanks @gogaz Installing twig did the trick. composer require

How do I access the _context variable within a macro in TWIG?

主宰稳场 提交于 2020-01-23 05:31:08
问题 I'm trying to access one of my twig variables in a macro. I know I can't do this directly. as with PHP functions, macros don't have access to the current template variables but the same page state: You can pass the whole context as an argument by using the special _context variable. What's the syntax for passing _context to the macro, and for accessing it within the macro? thanks 回答1: Consider the following example: 1) Create a variable in the current context {% set x = 42 %} 2) Declare a

symfony2 difference between error.message and error.messageKey

十年热恋 提交于 2020-01-23 02:15:09
问题 I am implementing a simple custom login form. I am following two different example , the official one http://symfony.com/doc/current/cookbook/security/form_login_setup.html and this other one https://knpuniversity.com/screencast/symfony2-ep2/logout#play which is substantially the same but with some differences. Giving a look at the login.html.twig of the two examples, one of the differences is in the error message reporting where the first reports <div class="error">{{ error.message|trans }}<

twig - building array in for loop

自作多情 提交于 2020-01-22 13:13:55
问题 is it possible to iteratively fill a twig array with values? {% for question in questions %} {% set multipleChoiceArray = [] %} {% for multipleChoice in question.multipleChoiceAnswers %} {% set multipleChoiceArray = multipleChoiceArray|merge( multipleChoice.answerText ) %} {% endfor %} {% endfor %} the problem is here multipleChoiceArray|merge(multipleChoice.answerText) when i try to pass an array for example with key = loop.index like {% set multipleChoiceArray = multipleChoiceArray|merge({

How can I check other users or role permissions in the template? symfony2

≡放荡痞女 提交于 2020-01-22 05:30:17
问题 I'm building this user manager, where admins can change permission of a group or user. I don't want to use the FOS user bundle, because I want to customize alot. I found out I can give permissions to another user in the controller, but how can I read the permissions of another user/role? And is it possible to read these permissions of another user/role in the template? The Ideal way I would like to do this is: (a page to view users in a group and the permissons) 1 Get all objects and users in

Symfony 2 - Form theming - Overriden block renders two times

我只是一个虾纸丫 提交于 2020-01-17 06:26:08
问题 I'm trying to customize a theme form submit button but this button is being rendered two times. The first time when the block is overriden and the second time when i'm using it in my form. Here is the code and the result. Thanks a lot. {# src/YagoQuinoy/Simple/BlogBundle/Resources/views/Blog/searchArtciles.html.twig #} {% form_theme form _self %} {% block submit_widget %} <button><i class="fa fa-bicycle"></i></button> {% endblock submit_widget %} {{ form_start(form, {'attr': {'novalidate':

Populate twig template from external api

孤者浪人 提交于 2020-01-17 03:05:30
问题 I am building a Drupal 8 site and am new to the twig templating engine. For one specific content type I would like to make a call to an external restful api and render some of the returned data as fields in the twig template. I have an internal id to call out to the API and I would like to embed in the template: The api call set a number of variables from the call render the result (with some logic if it does not exist) Is this something that is easy to do with twig and drupal 8? As a