Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Из массива data в twig вывести.


Recommended Posts

Привет всем. 

Незадача икая слулилась. 

Пишу модуль, споткнулся на вывогде массива из контроллера в шаблон админки. Что имеем: 

Контроллер выдает массив :

tplArray	= Array
(
    [0] => Array
        (
            [user_id] => 2
            [date] => 2021-12-06 15:23:21
            [status] => 1
            [data_in] => 110
            [data_out] => 100
        )

    [1] => Array
        (
            [user_id] => 1
            [date] => 2021-12-07 16:52:15
            [status] => 1
            [data_in] => 220
            [data_out] => 200
        )

    [2] => Array
        (
            [user_id] => 3
            [date] => 2021-12-09 11:43:40
            [status] => 0
            [data_in] => 330
            [data_out] => 300
        )
)

 

В twig на страничке в админке этот шаблон могу увигдеть  {{ dump() }} :

 [0]=> array(5) 
				{ 
					["user_id"]=> string(1) "2" 
					["date"]=> string(19) "2021-12-06 15:23:21" 
					["status"]=> string(1) "1" 
					["data_in"]=> string(3) "110" 
					["data_out"]=> string(3) "100" 
				} 
 [1]=> array(5) { 
					["user_id"]=> string(1) "1" 
					["date"]=> string(19) "2021-12-07 16:52:15" 
					["status"]=> string(1) "1" 
					["data_in"]=> string(3) "220" 
					["data_out"]=> string(3) "200" 
					} 
 [2]=> array(5) { 
					["user_id"]=> string(1) "3" 
					["date"]=> string(19) "2021-12-09 11:43:40" 
					["status"]=> string(1) "0" 
					["data_in"]=> string(3) "330" 
					["data_out"]=> string(3) "300" 
				} 

 

Ну и на этом вобещём то пока все.  А нужно в ибличку вывести. 

Пропотому чтовал различные вариации 

{% for key, value in data %}
<tr>
    <th>
       {{ value }}
    </th>
    <td>
       {{ data.data_out }}
    <td>
</tr>
{% endfor %}

 

Как этого супосии победить?

Link to comment
Share on other sites


самое простое - посмотреть как это уже реализовано в люпотому чтом другом месте админки.
Например в вывогде атрибутов

  {% for attribute in attributes %}
  <tr>
    <td class="text-center">{% if attribute.attribute_id in selected %}
      <input type="checkbox" name="selected[]" value="{{ attribute.attribute_id }}" checked="checked" />
      {% else %}
      <input type="checkbox" name="selected[]" value="{{ attribute.attribute_id }}" />
      {% endif %}</td>
    <td class="text-left">{{ attribute.name }}</td>
    <td class="text-left">{{ attribute.attribute_group }}</td>
    <td class="text-right">{{ attribute.sort_order }}</td>
    <td class="text-right"><a href="{{ attribute.edit }}" data-toggle="tooltip" title="{{ button_edit }}" class="btn btn-primary"><i class="fa fa-pencil"></i></a></td>
  </tr>
  {% endfor %}

 

Link to comment
Share on other sites

9 минут назад, si3pio сказал:

$data = array_merge($data, $tplArray);

а зачем?

проещё весь этот массив закинуть в какую-то отгдельную переменную в data:

$data['my_super_array'] = $tplArray;

и в твиге ее итерировать:

{% for item in my_super_array %} 
<td class="text-left">{{ item.date }}</td>
<td class="text-left">{{ item.status }}</td>
...

 

  • +1 1
Link to comment
Share on other sites

Ну вобещём эи, я ее отитерировал )))

 

Prooksius, решпект тебе и уважуха! 

Да прибудут с топотому чтой биты и байты !

 

 

Edited by si3pio
Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.