i think, i have a typical use case and i don't bring it to a working state (as a designer) ...
fundament:
- node template for the content type the field collection is used
- i don't want to use field templates (i already removed all surrounding tags in my basic field.tpl)
- i want to print the node fields directly into the node.tpl - no general content render
- i have to get rid of all needless wrapper stuff generated by field collection (clearfixes etc.) - i want a clean markup (hack of the module would be ok)
- including dealing empty fields
- i would pay money for it (tell me the amount you need) + i will post the solution here
structure:
- content type template: node--nodeblock.tpl.php
- field collection: field_coll_img_link (unlimited)
- 2 sub fields: field_coll_img_single (single value) + field_coll_link_single (single value)
- the image field display, set in the render settings, is only the raw scaled image - for example:
<img alt="" src="http://www.foo.com/sites/default/files/styles/thumb-sidebar/public/foo.png" />
- the link field display, set in the render settings, is only the raw url - for example:
http://foo.com/
task:
- let the link surround the image - for example:
<a href="http://foo.com/"><img alt="" src="http://www.foo.com/sites/default/files/styles/thumb-sidebar/public/foo.png" /></a>
it would be wonderful if somebody could solve this for me with normal $content values or entity API wrappers ...
thanks a lot + best regards sb
Comments
Comment #1
guybedford CreditAttribution: guybedford commentedI had this same issue - managed to solve it with the following php code in the template:
In my case, the name of the field collection is: "field_tabs"
This field collection contains two fields: "field_tab_name" and "field_tab_content"
The php is included below, which is included in "node--node-type.tpl.php".
For many field collection values, the $field_collection array can be looped for the different groups. This is in the case of one value.
Note also the above code includes no error checking, language checking, and ideally you should place this in the node preprocessor!
Comment #2
Morasta CreditAttribution: Morasta commentedSimilar issue as OP and #1. In my case I had an unlimited number of values. Here's a modification that let me loop through each instance and print them out.
In this example I needed two fields, date and description, together on a single row. Left the divs in to show structure for those who need it.
Comment #3
morybel CreditAttribution: morybel commentedThis is exactly what I needed !! Thanks!!!! Here's what I did to include it in html (for formating purposes). No errors, datas gets displayed correctly in my table.
However, whenever I hit F5 for refreshing I keep having these errors:
Notice : Undefined index: 8 in include() (ligne 81 in /sites/mysite/theme/node--annexe_a.tpl.php).
Notice : Trying to get property of non-object in include() (ligne 81 in /sites/mysite/theme/node--annexe_a.tpl.php).
Line 81, line 82, line 83 etc... an error for each header in my table.
I clear my caches, they disappears. Then I hit F5 and here they are again.
I'm not a programmer, so I would love for anyone to point me to my error.
Thanks for everything.
EDIT:
Comment #4
morybel CreditAttribution: morybel commentedWould any of you know how to make a numbered list with this? ($count ?)
Thanks
Comment #5
jorlowsk CreditAttribution: jorlowsk commentedOk, so I have this half working which is a lot further than where I was three weeks ago. I have a field collection named "field_project". In that I have two fields named "filed_projectphoto" which is an image and "field_projectphotocaption" which is text. Field "field_projectphotocaption" prints to screen just fine, however, (tested with a couple of different image fields) I can't get an image to print to screen.
In turn I am also getting this error:
Notice: Undefined index: value in include() (line 6 of /home/whitepoi/public_html/dev.followvue.com/sites/all/themes/VUE/node--projects.tpl.php).
Notice: Undefined index: value in include() (line 6 of /home/whitepoi/public_html/dev.followvue.com/sites/all/themes/VUE/node--projects.tpl.php).
Any help would be appreciated. Thanks in advance.
- Jeff
Comment #6
morybel CreditAttribution: morybel commentedHi Jorlowsk,
I also had this error notice. It turned out I had a default value on one of my fields that caused to add a extra blank line at the end of my table. Deleting the default value (and the extra blank line) made all the errors disappears.
For your image, try this:
<?php print $field_collection[$idx]->field_projectphoto['und'][0]['uri'];?>
Hope this help.
Comment #7
quasi CreditAttribution: quasi commentedThis would be the code adapted for the counter:
Comment #8
morybel CreditAttribution: morybel commentedThank you soooooooo much... as of flexifield in D6 I had to put [$count] in every array. That was my mistake. I'm very greatfull for your help.
:-)
Comment #9
sachbearbeiter CreditAttribution: sachbearbeiter commentedthanks to all posters ...
Comment #10
Blue CreditAttribution: Blue commentedI have a problem with theming field collection. I want to create a loop and I have a field called field_earth inside field_helloworld that displays unlimited images.
Problem is that :
print $field_collection[$idx]->field_earth['und']['0']['value'];
it does not display any image.If i print
print $field_collection[$idx]->field_earth['und']['0']['uri'];
I do get values (public://logo.png) but I don't get the links to the images.Someone can show me how can I display all images?
Many many thanks with this.
Comment #11
morybel CreditAttribution: morybel commentedYou should check here:
http://robotlikehuman.com/web/printing-cck-content-field-values-drupal-7
This whole discussion is about templating a node with drupal 7 content field. Very instructive. There is a comment about how to print images from a field.
Hope this helps.
Comment #12
jeffglenn CreditAttribution: jeffglenn commentedI have been looking over this and other posts for quite sometime and I still can't seem to figure this out...
In D6 I was able to easily node_load(); in a Multi-Group and create a foreach loop to load the data I needed from each field. Here's the code I have in D6:
Now I'm trying to do the same thing with Field Collections. I figured I could use the entity_load(); like this:
<?php $field_collection = entity_load('field_collection_item', array($item_id)); ?>
then krumo(); that variable and pull the information needed. However as you all probably already know that doesn't work. I've tried quite a few different combinations and none seem to work.
Any help at all would be appreciated
Comment #13
jeffglenn CreditAttribution: jeffglenn commentedFor anyone interested I thought I would post a follow-up. I got it working with this code. Basically the same principle just using Field Collection Instead of MultiGroups.
Comment #13.0
jeffglenn CreditAttribution: jeffglenn commentedfield_coll_img_single (single value) + field_coll_link_single (single value)
more clear now
Comment #14
jmuzz CreditAttribution: jmuzz commentedTheming around field collection is still a work in progress. See #1157794: Move markup to template files and improve theming in new 2.x branch.
It sounds like you guys have found workarounds that will work in your situations so I will close this.