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

sgabe’s picture

Assigned: amins » Unassigned
Priority: Major » Normal

This seems to be a site building issue, I think you need the Display Suite module.

amins’s picture

@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.

sgabe’s picture

Well 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.

  print render($build['field_newsletter_announcements']) 
amins’s picture

Thanks @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.

sgabe’s picture

Title: Accessing a CCK field in Mimemail » Accessing a CCK field in Simplenews
Project: Mime Mail » Simplenews
Version: 7.x-1.0-alpha1 » 7.x-1.x-dev
Status: Active » Closed (fixed)

Moving issue to the right place.

maxq10’s picture

I 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.

andyanderso’s picture

Thanks for posting this. I have found it very helpful.
I can access custom cck fields with:

  print render($build['field_bottom_line'])

Does anyone know how to just access field values without the labels?
I printed out the $build data with:

print_r($build['node'];

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?

andyanderso’s picture

Ok. I think I finally figured it out:
print $build['field_bottom_line']['#items'][0]['value']
gets me the actual field value.

andyanderso’s picture

Now all I am stuck on is how to get the created date/time and the author name. It seems like they should be:

$build['name']
$build['created']

but neither of those work.

tchopshop’s picture

How 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!

andyanderso’s picture

Did you try?

hide($build['field_myfield'])

Instead of using $content['field_myfield']

tchopshop’s picture

Yes, I did.

dagoodgamez’s picture

Issue summary: View changes

I'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?

kreatil’s picture

@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']) ?>

bobbia’s picture

Thanks 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:

<?php print render($build['field_image']); ?>
<?php print render($build['field_appdate']); ?>
<?php print render($build['body']); ?>

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!

amins’s picture

Issue summary: View changes