2017-05-24 12 views
0

フィールドコレクションの個々のフィールドをレンダリングして、フィールドの順序、フィールドの内容、ラッピングDOMノードの削除などを特定の基準に応じて行う必要があります。個別のFieldCollectionItemEntityフィールドをレンダリングする

私はthis threadから読んできましたが、このフィールドコレクションレンダラーが動作していない理由を理解できません。

単に何も出力しません。 print render出力する前dpm($item_object);権利を追加

node--component-icon-promo.tpl.php

<? if (!empty($content['field_icon_promo_items'])) : ?> 

    <div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>> 

    <?php foreach ($content['field_icon_promo_items']['#items'] as $entity_uri): ?> 
     <?php 
     $item = entity_load('field_collection_item', $entity_uri); 
     ?> 

     <?php foreach ($item as $item_object): ?> 

     <?php print render($item_object->field_cta); ?> 

     <?php endforeach; ?> 
    <?php endforeach; ?> 

    </div> 

<? endif; ?> 

Field output

そして<?php print render($item_object); ?><?php print render($item_object->field_cta); ?>を変更するだけでエラーになります。

Recoverable fatal error: Object of class FieldCollectionItemEntity could not be converted to string in include() (line 99 of /var/www/html/sites/all/themes/xerox/templates/node--component-icon-promo.tpl.php).

私は、$ item_objectだけでは、render doesn't likeオブジェクトであるため、それは知っています。 APIのフィールドコレクションビットはちょうど完全な混乱のように思えます。

ご協力いただければ幸いです。

答えて

1

はentity_metadata_wrapper使用して、この方法のようにそれを使用することをお勧め:メタデータラッパ訪問の詳細なヘルプについては

<? if (!empty($content['field_icon_promo_items'])) : ?> 

    <div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>> 

    <?php foreach ($content['field_icon_promo_items']['#items'] as $entity_uri): ?> 
     <?php 
     $item = entity_load('field_collection_item', $entity_uri); 
     ?> 

     <?php foreach ($item as $item_object): ?> 

     <?php 
      $wrapper = entity_metadata_wrapper('field_collection_item', $item_object); 
      $field_cta = $wrapper->field_cta->value(); 
      //render your values with your own html or using theme_link function 
     ?> 

     <?php endforeach; ?> 
    <?php endforeach; ?> 

    </div> 

<? endif; ?> 

this link

+0

私はそれが必要な非常に似このコードは動作しませんでしたが、メタデータラッパーは私を正しい方向に押し込んだ! – Hawxby

関連する問題