2016-06-20 11 views
0

私の質問は、Symfony FrameworkのTWIG Viewにデータをどのように送ることができるかです。 私はそれに向かってデータを渡している行動が必要だろうと思います。Symfony Pass表示するデータ

だから私はstartetデータベースに接続し、私がどのように見えるのアレイに必要なデータを追加アクションの作成:私はこのレンダリング終わり

$data[$name] = $name; 

return $this->render('PoolLinkmotorBundle:Page:index.html.twig', array('motos' => $data)); 

を何私は今私のビューで行う必要がありますか? は、私は私が

{% for data in motos %} 
       {{ //Dont know what to do here }} 
    {% endfor %} 

のように任意のアイデアをsomethinkを行うことができます思いましたか?

UPDATE:

これは私がデータを追加する必要があり図です。それは「macros.twig.html」というファイルにあります。

{% macro showPagesBodyCell(tableOption, page, type, previousPageId) %} 
{% set id = tableOption.id %} 
{% set class = 'row-' ~ id ~ ' ' ~ tableOption.class %} 
{% if id == 1 %} 
    <td class="url {{ class }}"> 
     <a id="prospect-{{ page.id}}" href="{{ path('pool_linkmotor_pages_view', {id:page.id}) }}" title="{{ page.full }}"> 
      {{ page.fullForDisplay }} 
     </a> 
    </td> 
{% elseif id == 2 %} 
    <td class="lm-actions {{ class }}"> 
     <div class="uk-button-group"> 
      <a title="{% trans %}Open{% endtrans %}" class="uk-button lmexternal" href="{{ path('pool_linkmotor_anonymizer') ~ '?url=' ~ page.full }}" target="_blank"> 
       <i class="uk-icon-external-link"></i> 
      </a> 
      <a title="{% trans %}Search for backlinks{% endtrans %}" class="uk-button slow" href="{{ path('pool_linkmotor_pages_search_backlinks', {id:page.id}) }}"> 
       <i class="uk-icon-link"></i> 
       <i class="uk-icon-plus icon-backlink"></i> 
      </a> 
     </div> 
    </td> 
{% elseif id == 3 %} 
    <td class="{{ class }}"> 
     {% if page.statusMayBeChangedByUser(app.user) %} 
      <form class="autosubmit" action="{{ path('pool_linkmotor_pages_edit', {id:page.id}) }}" method="POST"> 
       <input type="hidden" name="inline" value="true"> 
       <input type="hidden" name="previous" value="{{ previousPageId }}"> 
       <select name="page_edit[status]"> 
        <option value="1"{% if page.status.id == 1 %} selected="selected"{% endif %}> 
         {% trans %}New{% endtrans %} 
        </option> 
        <option value="2"{% if page.status.id == 2 %} selected="selected"{% endif %}> 
         {% trans %}Relevant{% endtrans %} 
        </option> 
        <option value="3"{% if page.status.id == 3 %} selected="selected"{% endif %}> 
         {% trans %}Not relevant{% endtrans %} 
        </option> 
        <option value="4"{% if page.status.id == 4 %} selected="selected"{% endif %}> 
         {% trans %}1. Contact{% endtrans %} 
        </option> 
        <option value="5"{% if page.status.id == 5 %} selected="selected"{% endif %}> 
         {% trans %}2. Contact{% endtrans %} 
        </option> 
        <option value="8"{% if page.status.id == 8 %} selected="selected"{% endif %}> 
         {% trans %}In progress{% endtrans %} 
        </option> 
       </select> 
      </form> 
     {% else %} 
      {{ page.status.name|trans }} 
     {% endif %} 
    </td> 
{% elseif id == 4 %} 
    <td class="{{ class }}">{{ valueOrSpinner(page.authority, 0) }}</td> 
{% elseif id == 5 %} 
    <td class="{{ class }}">{{ valueOrSpinner(page.subdomain.domain.authority, 0) }}</td> 
{% elseif id == 6 %} 
    <td class="{{ class }}"> 
     {% if not page.subdomain.domain.notYetCrawled and not page.subdomain.domain.firstYear %} 
      {% trans %}n/a{% endtrans %} 
     {% else %} 
      {{ valueOrSpinner(page.subdomain.domain.firstYear) }} 
     {% endif %} 
    </td> 
{% elseif id == 7 %} 
    <td class="{{ class }}">{{ valueOrSpinner(page.subdomain.domain.netPop|localeNumber, null) }}</td> 
{% elseif id == 8 %} 
    <td class="{{ class }}">{{ valueOrSpinnerOrInfo('sistrix', page.subdomain.sichtbarkeitsindex|localeNumber(4), null) }}</td> 
{% elseif id == 9 %} 
    <td class="{{ class }}">{{ valueOrSpinnerOrInfo('xovi', page.subdomain.ovi|localeNumber(2), null) }}</td> 
{% elseif id == 10 %} 
    <td class="{{ class }}"> 
     <a href="{{ path('pool_linkmotor_domains_view', {id:page.subdomain.domain.id}) }}" class="domain"> 
      {{ page.subdomain.domain.nameForDisplay }} 
     </a> 
    </td> 
{% elseif id == 11 %} 
    <td class="{{ class }}" style="min-width: 75px;"> 
     {% if page.subdomain.vendor %} 
      <a class="uk-text-muted" href="{{ path('pool_linkmotor_vendors_view', {id:page.subdomain.vendor.id}) }}" 
       data-uk-tooltip="{pos:'bottom'}" title="Subdomain-{% trans %}Vendor{% endtrans %}: {{ page.subdomain.vendor.displayName }}"> 
       <i class="uk-icon-user"></i> <small>{% trans %}show{% endtrans %}</small> 
      </a> 
     {% elseif page.subdomain.domain.vendor %} 
      <a data-uk-tooltip title="{{ page.subdomain.domain.vendor.displayName }} {{ page.subdomain.domain.vendor.phone }}" href="{{ path('pool_linkmotor_vendors_view', {id:page.subdomain.domain.vendor.id}) }}"> 
       <i class="uk-icon-user"></i> <small>{% trans %}show{% endtrans %}</small> 
      </a> 
     {% else %} 
      <a class="uk-text-muted" href="{{ path('pool_linkmotor_domains_set_vendor', {id:page.subdomain.domain.id}) }}"> 
       <i class="uk-icon-plus-square"></i> <small>{% trans %}add{% endtrans %}</small> 
      </a> 
     {% endif %} 
    </td> 
{% elseif id == 12 and type == 'all'%} 
    <td class="{{ class }}">{{ page.assignedTo.displayName }}</td> 
{% elseif id == 13 %} 
    <td class="{{ class }}"> 
     {% if page.lastNote %} 
      <span data-uk-tooltip="{pos:'bottom'}" title="{{ page.lastNote.content }}"> 
       <i class="uk-icon-comment"></i> 
      </span> 
     {% endif %} 
    </td> 
{% elseif id == 14 %} 
    <td class="{{ class }}"><small>{{ page.lastModifiedAt|localeDate('d') }}</small></td> 

{% elseif id == 15 %} 

{% endif %} 

{%のendmacro%}

データの一部ここ 'のid == 15' に属しています。

UPDATE:

私は自分でそれを考え出しました。 私はちょうどちょうど渡しているデータは、配列を初期化し、データを入れてビューにアクセスすることができます。レンダリングは正しかった。 Forループ

+0

あなた」:それは文字列のみならhttp://twig.sensiolabs.org/doc/tags/for.html

しかしmotosをするだけでなく、文字列名配列、

$arrayExample = [ [0] => ['name' => 'Yamaha'], [1] => ['name' => 'Honda'] ]; // motos in twig {% for data in motos %} {{ data.name }} // will display Yamaha // Honda {% endfor %} 

する必要があります既にビューにデータを渡しました。どのようにレンダリングするつもりかを伝える方法はありません。 – ShiraNai7

+0

しかし、私は渡されたデータをどのように扱うことができますか? – Traxstar

+1

http://twig.sensiolabs.org/doc/templates.html – ShiraNai7

答えて

1

、あなたが確認できます。

$data['name'] = 'toto'; 

{{ myvartwig.name }} // NO LOOP 
+0

私はforループを使用できることを知っています。しかし、私は私の配列で何をすべきか分かりません。 私はnexample – Traxstar

+0

あるmoto.KEY {%がモトでモトため%}を呼び出す場合しています私はちょうど正確なuはpostet事をしようと試みたと私はまだ何も出力 – Snow

+0

を追加しました 何も起こりません... とモトが配列 – Traxstar

関連する問題