Use Code Snippets to "centralize" 100's of identical notifications [RESOLVED]

Hello,

I have literally hundreds of notifications (say 15 forms with 30 different notifications for each form entry), and it is extremely exhausting to open every notification if I just want to make a small change.

Hence, I decided to create shortcodes with the notification content, (by using the plugin Code Snippets (pro version)), so that I only need to change the content in one place.
(This could, of course, be done in the functions.php as well, I just find it easier to work with all the code snippets separated…)

This works rather well actually, with GF Conditional shortcodes and everything, but there is one thing I can’t figure out how to solve, and that is Merge tags.

Like this:

[/gravityforms] [gravityforms action="conditional" merge_tag="{Name(Firstname):1.3}" condition="isnot" value=""] This field is not the same as {OtherName:2}.[/gravityforms]

The code above would only output

This field is not the same as .

(The merge tag “{OtherName:2}” is not kicking in.)

I think I need to use php here (probably gform_notification and something with the Entry Object), but this is quite abow my head.

I hoped a simple
<?php $something = (rgar( $entry, '3' )); echo $something; ?>
would do, but that, of course, doesn’t work at all.

Can anyone help me out here?

Thanks upfront!

Can you please export your snippet and post that file somewhere, then share the link here? I’d like to see what filter you are using for this, along with the complete code. Thank you.

Hello Chris,

I ended up not using merge tags at all, and just use plain if/else with php. Example here:

// Add email content.

//Target the correct forms
add_filter( 'gform_notification_27', 'email_content', 10, 3 );
add_filter( 'gform_notification_29', 'email_content', 10, 3 );
add_filter( 'gform_notification_30', 'email_content', 10, 3 );
add_filter( 'gform_notification_33', 'email_content', 10, 3 );
add_filter( 'gform_notification_34', 'email_content', 10, 3 );
add_filter( 'gform_notification_35', 'email_content', 10, 3 );
function email_content( $notification, $form, $entry ) {
    //Use on the following notifications
    if( 
		($notification['name'] == 'Notification something' ) ||
		($notification['name'] == 'Notification something else' ) ||
		($notification['name'] == 'Rejection' ) ||
		($notification['name'] == 'Approval today' ) ||
		($notification['name'] == 'Approval tomorrow' ) ||
		($notification['name'] == 'Administrator notification' ) ||
		($notification['name'] == 'Customer notification' ) ||
		($notification['name'] == 'The copy to someone' ) ||
		($notification['name'] == 'The copy to someone else' ) ||
		($notification['name'] == 'Something completely different' ) ) {
			
        //The needed fields (in this theoretical scenario)
        $firstname = rgar( $entry, '6.3' ); 
        $lastname = rgar( $entry, '6.6' ); 
        $signature = rgar( $entry, '39' ); 
        $typeofmission = rgar( $entry, '35' ); 
        $sellername = rgar( $entry, '31' ); 
        $selleremail = rgar( $entry, '59' ); 
        $sellerphone = rgar( $entry, '34' ); 
        $sellertitle = rgar( $entry, '33' ); 
		
		//The email Content
		$hello = 'Hello '.$firstname.' '.$lastname.',<br><br>';
		
		//If not signed (The troublesome merge tags)
		if ( empty($signature) ) {		
			$sometext = 'Blah blah '.$typeofmission.'.<br><br>Blah Blah.';	
		}
		//if signed
		else {
			$sometext = 'Blah blah '.$typeofmission.'.';
		}
		$othertext = '<br><br>Blah Blah <a href="mailto:'.$selleremail.'">'.$selleremail.'</a>, or phone <a href="tel:'.$sellerphone.'">'.$sellerphone.'</a>.';
		
		//Signature
		$regards = '<br><br>Best regards<br><br><'.$sellername.'<br>';
		$regardstitle = '<span style="font-size:.9em">'.$sellertitle.'<br>My Company<br></span>';
		
		
		$notification['message'] = ''.$hello.''.$sometext.''.$othertext.''.$regards.''.$regardstitle;
    }
    //return altered notification object
    return $notification;
}