1

Simplenews Scheduler is working well for me to send a weekly email which contains an attached view (using EVA) of nodes.

I would like the newsletter to only send if the attached view contains nodes, so that empty newsletters are not sent.

I can see that this should be possible using the 'Additionally only create newsletter edition if the following code returns true' field on the Newsletter > Send newsletter according to schedule page. I am currently using this (which always produces a newsletter regardless of whether nodes are displayed in the view):

if(views_get_view('job_type_c_list')) {
      return true;
}

I have tried using the overall length of the node body to try to work out if a view is present. (I don't know if the tokens can be used in this field or not):

if(views_get_view('job_type_c_list')) {
     $myvar = [node:body:?];
     if(strlen($myvar) >= 30) {
           return true;
      }
}

When i was working with PHP in the body of the node I was able to evaluate whether EVA was returning nodes by using

<?php
    $view = views_get_view('job_type_c_list');
    $printedview = $view->preview('default');

    $myvar = (string)$printedview;

    if(strlen($myvar) >= 1000) {
           print "VIEW ATTACHED";
    }

    else if(strlen($myvar) < 1000) {
           print "NO VIEW ATTACHED";
    }
?>

The above code is clearly not the most elegant, but it worked in the node itself. Unfortunately it didn't work in the 'Additionally only create newsletter edition if the following code returns true' Simple news scheduler field.

I have struggled with this for quite some time and would really appreciate some help. Code suggestions would be great, but failing that knowing 'If I can use tokens in the field?' and 'why does the PHP in this field behaves differently to PHP the node itself?' would also be very helpful.

I have had an issue open in the module issues page for a few days now, but it has not received any responses.

0

did you find out a way to do it? In your example, using views_get_view will always return true, because even if the view has no result, the result of the function will be an object, so will not be empty. If you're using views_get_view, you will always have a <div> inside. You should get the view, then do a preview and then check if there is results or not.

Like this:

 $view = views_get_view('view_id');
 $print_view = $view->preview('display_id');
 if(!empty($view->result)) {
   print $print_view;
 }

I would be happy to know if you found a solution to this because I will face the same problem in a couple of days, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.