Is it possible to use this module to embed a rule using the Rules "Send mail" action? I tried enabling the insert view filter for all available text formats, but it didn't work out of the box; I can embed views in nodes, but not the body of an email sent by Rules.

Comments

ptmkenny created an issue. See original summary.

michaeldknox’s picture

Did you ever find an answer? I'm trying to do the same thing.

thomasmurphy’s picture

I looked into this too, but it didn't work. I've managed to embed the view using one line of PHP though, based on
https://api.drupal.org/api/views/views.module/function/views_embed_view/...

e.g.

print views_embed_view('your_view', 'you_display');

hschott’s picture

I'm trying to do the same thing. NO luck. thomasmurphy, where did you put this line of code? Are you doing this through Rules? I tried putting it in the rules value for the body, but it just prints it out the line exactly in the email, not getting the view. Is it possible to put php in the rules/ action/ sendmail/ body?

thomasmurphy’s picture

Hi hschott, yes it's in a rule.

Are you putting the php inside <?php ?> tags? Without them Drupal will treat the PHP as text rather than interpreting it. This can work in the message body, or I'm defining a text variable as an action in the view and including the variable in message body, which was easier to debug in my case.

Also, you need an embed type view display, which you need to enable via the view settings (/admin/structure/views/settings)

Ideally we could do with a module which allows views embedding in rules via tokens, to avoid putting PHP in the database, but I'm not aware of one that works and don't have the time to put into making one, ho hum.

hschott’s picture

Thanks for responding thomasmurphy. I do have the php tags. I did finally get it to work, but not sure how exactly. All I did was enter an email address in the from value, even though it says you can leave it blank and it will use the sitewide email, which I do have set.

renatog’s picture

Status: Active » Reviewed & tested by the community

Hi guys.

I'm checking it and #5 really make sense. It helps me here.

renatog’s picture

Status: Reviewed & tested by the community » Fixed

Thank you for your help @thomasmurphy

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

TimelessDomain’s picture

Is this still the only way to embed an insert view into a rules email? Can you please provide the full coding to make this work?
Is it <?php print views_embed_view('your_view', 'your_display');?>?

TimelessDomain’s picture

Title: Can I use this module to insert a view into the body of a rules "send mail" action? » Insert a view into the body of a rules "send mail" action
Category: Support request » Feature request

This should be working with the html mail module but it doesn't. See https://www.drupal.org/project/htmlmail/issues/3161081

TimelessDomain’s picture

<?php print views_embed_view('your_view', 'your_display');?> does work! Just remember to turn on the php filter module and enable it in text formats

I'm using the HTML Mail module to enable Post-filtering "You may choose a text format to be used for filtering email messages after theming. This allows you to use any combination of over 200 filter modules to make final changes to your message before sending."