I posted this issue in a wrong place, sorry for duplication.
I am trying to use Mimemail and Simplenews to send out newsletters to my subscribers. I know that there is a $body variable which I was able to print in the sent email. I would like to have access to cck fields within $body variable, is that possible?. Specifically, I have a cck field in my newsletter content type called "field_newsletter_announcements" which I would like to print out at the top of the newsletter. Apparently the $node variable is not available and all the structures suggested by devel module such as field_newsletter_announcements['und'][0]['value'] are useless.
I think sending a newsletter should be a basic feature in a content management system like Drupal. I appreciate any help in this regard.
Comments
Comment #1
sgabe commentedThis seems to be a site building issue, I think you need the Display Suite module.
Comment #2
amins commented@sgabe, I already have Display Suite module but I believe this is not the problem. The announcement field and other field are showing in the node but not in the sent email. Please check this link to see an example of such node http://www.computervisiononline.com/newsletter/test-newsletter-july-16
Note that the announcement field is showing in this node on top of the newsletter.
but when I use the same php code, as in the node template, in the mimemail-message.tpl.php, the variable node is not accessible anymore and I get the following error message:
Notice: Undefined variable: node in include() (line **** of /home/****/public_html/****/sites/all/themes/****/templates/mimemail-message.tpl.php).
This error happens when I send a test email and consequently the announcement field along with other fields are not showing in the sent email.
I thought maybe $body variable can be used instead of $node variable but I could not find a way to access specific fields within $body variable. Am I missing something?
I appreciate your help in advance.
Comment #3
sgabe commentedWell I still don't think this is a Mime Mail issue.
You need to customize the simplenews-newsletter-body.tpl.php. If you set up either supported view modes (email_plain, email_html, email_textalt) the $build variable will contain also your custom fields.
Comment #4
amins commentedThanks @sgabe, you finally saved me. I was confused and I still don't know what mimemail-message.tpl.php is for. I just removed this template and used simplenews-newsletter-body.tpl.php to theme the sent email and works the way that I wanted.
Comment #5
sgabe commentedMoving issue to the right place.
Comment #6
maxq10 commentedI had been trying to do the exact same thing here and was stumped. Turns out I was just being an idiot, and finding this thread saved me. Thank you so much.
Comment #7
andyanderso commentedThanks for posting this. I have found it very helpful.
I can access custom cck fields with:
Does anyone know how to just access field values without the labels?
I printed out the $build data with:
and I have tried several variations of this:
$build['field_bottom_line']['und'][0]['value'];
I have used
$build->field_bottom_line['und'][0]['value'];
both with print_r, echo, render etc...
Any one figured out how to do this?
Comment #8
andyanderso commentedOk. I think I finally figured it out:
print $build['field_bottom_line']['#items'][0]['value']gets me the actual field value.
Comment #9
andyanderso commentedNow all I am stuck on is how to get the created date/time and the author name. It seems like they should be:
but neither of those work.
Comment #10
tchopshop commentedHow do I hide fields from
print render($build);
so that I can display them separately from the overall render build?
Something like hide($content['field_myfield']); doesn't seem to work.
thanks!
Comment #11
andyanderso commentedDid you try?
hide($build['field_myfield'])
Instead of using $content['field_myfield']
Comment #12
tchopshop commentedYes, I did.
Comment #13
dagoodgamez commentedI'd like to access a field to display as a link inside the mail.tpl template inside the href="..". I've tried print render($build['field_link_mail']) "> but is not working. ANy idea how to do it?
Comment #14
kreatil commented@dagoodgamez:
You could try
<?php print $build['my_field_machine_name']['#items'][0]['value'] ?>Edit:
The above code didn't work for me on production site. This is my solution now:
<?php print render($build['my_field_machine_name']) ?>Comment #15
bobbia commentedThanks to all for the very helpful advice!
In my template, I replaced:
<?php print render($build); ?>(which printed all the fields in the node)With:
And I was able to only have the 3 CCK fields in my newsletter.
I know this is basically duplicated information. But, sometimes, it helps to have multiple examples (for me, at least).
Thanks again!
Comment #16
amins commented