I need to print the contents of a node containing a multigroup. My multigroup contains the following fields. Currently, I have this in the email:
Course 1
Name: <?php print $node->field_courses[0][value]; ?>
Number: <?php print $node->field_coursenumber[0][value]; ?>
College: <?php print $node->field_collegecourse[0][value]; ?>
Credits: <?php print $node->field_gradcredits[0][value]; ?>
Duration: From: <?php print $node->field_cduration[0][value]; ?> To: <?php print $node->field_cduration[0][value2]; ?>
This works fine, but how do I show any other item created by the user? For example, I posted Course 1, but what if the user creates a Course 2 containing all the same fields?
Comments
Comment #1
markus_petrux commentedYou should iterate through delta values as if the fields where defined with multiple values without multigroup. ie.
[0]is just the first value, but there may be more, so you should do a loop.Comment #2
markus_petrux commentedAssuming the support request is resolved. Please, re-open if there's still anything else that needs clarification. Thanks
Comment #3
ballerjones commentedAs much as I appreciate your response, I am very much a PHP newb, so I learned very little. I have heard of delta and loop, but I have no idea what they are or how to use them. I will do some research, but if you could post some code leading me in the right direction, that would be great.
Comment #4
markus_petrux commentedWell, there is always more than one way to do it, but maybe it could be something like this:
If you need further assitance, then I would suggest asking in the forums.
Comment #5
ballerjones commentedUnfortunately, the code you posted doesn't play nice with email sent by Rules. It fails to send, indicating the PHP could not parse. My suspicion is that your code is too complex, but only because the task is too complex. I may need to find a new workaround entirely.
Comment #6
markus_petrux commentedHere's something you can do to view the structure of the node. Enter the following in the message body option of the rule:
var_export($node);Yes, my code in #4 is not correct. I was using foreach incorrectly. Here's probably a better version:
I haven't tested this, so there may be errors. I'm sorry, but I don't know how to help you debug PHP code executed in rules.
Comment #8
jgarbe commentedThanks for this code, markus. I was using the multi-group in conjunction with the Content Profile node-type for a community, and it wasn't automatically outputting it (not surprising). Here's my version--the same syntactically, just resulting in different output:
results in:
Hopefully this will help other chowderheads like me. Great module!