Template meta tag substitution extension point

This example provides a custom extension to meta tag substitution processing.

sub EMP_SubstituteCustomMetaTag {
    my $metaTagParts_ref  = shift; # a reference to an array
    my $entityDefObj      = shift;
    my $isHTMLContent     = shift;
    my $isTest            = shift;
    
    # This routine provides a custom extension to the meta tag substitution processing.
    # If none of the built-in meta tags is sufficient for the HCL Compass Admins,
    # this extension enables admins to add their own meta tags. Explore the
    # EXPRESSION meta tag beforehand, because most needs will be met by
    # using that facility.  Keep in mind that you can call functions that are defined in the 
    # schema too. This customization point was designed to be used where 
    # you plan to test the function or to switch between HTML output and plain text
    # 
    # Parameters:
    # metaTagParts_ref - This is a reference to an array of the decoded parts of the metatag as read from the
    #                    template provided.  The 0 element is the name of the metatag whille any other
    #                    elements that may be present hold parameters decoded from the original input.
    #                    The original input is split on "::" boundaries.  The complete original tag can
    #                    be reconstituted with this statement 
    #                    $origMetaTag = join("::", @{$metaTagParts_ref});
    #  entityDefObj    - This is the HCL Compass Entity Def object for the record type to which the template pertains
    #  isHTMLContent   - This is a boolean flag that, when set to 1, means you can render the result as properly formed
    #                    HTML if desired. Otherwise, whatever you return will be treated as plain text.
    #  isTest	       - This is a boolean flag and, when set to 1, indicates that you should return any Error that the expanding the Tag may 
    #                    generate AND NOT the value. Returning a null string in isTest mode means there were no errors.
    #                    This feature is used to validate the usage of a tag.
    
    EMP_DebugOut("START - Add custom meta tags");
    my $errorTags = "";     # Put any error text in this variable. This will be displayed in the Debug window on the EmailPlusTemplate
    my $fieldValue = "";    # Put the result of the MetaTag expansion in this variable. This value will be included in the EmailPlus notification
    
    # Process the custom tags
    
    my $customTag = lc($metaTagParts_ref->[0]);

    # Add your processing here
    # ========================
    # Note that the meta tag is converted to lower case. Also, put all literal values should also be in lower case.
    # This handles the situation when the template rule writer uses mixed or upper case for the tag name.
    
    if ($customTag eq "nameoftemplate") {
        # This is an example of a custom metatag that returns the unique name of the EmailPlusTemplate template
        # In the EmailPlusTemplate template, you would use the #@NAMEOFTEMPLATE@# meta tag, which is not case sensitive		
			if ($session->HasValue("EMP::CONTEXT")) {
	    	my $context = $session->GetNameValue("EMP::CONTEXT");
			my($ruleName,$templateName) = split(/\|\|/,$context);
			$fieldValue = $templateName;
			# The unique TemplateName consists of 3 parts : RecordType TemplateKind TemplateName
		}
		else {
		    # If the EMP::CONTEXT session variable is not defined then return an error message as the result
		    my $errmsg = 'TemplateName could not be established using the MetaTag: '.$metaTagParts_ref->[0];

            # Use the function EMP_MakeEmbeddedErrorMessage to format the error if the message body format is HTML
			$fieldValue = EMP_MakeEmbeddedErrorMessage($errmsg,$isHTMLContent);
		}
    }
    # ================================================
    # This dummy is for test only and can be removed START-> 
    elsif ($customTag eq "dummy") {
        $fieldValue = "Customized test tag ".localtime();
    }
    # <- END This dummy is for test only and can be removed 
    # ================================================
    else {
        # Catches Undefined tags
        $errorTags .= "ERROR: Undefined MetaTag: ".$metaTagParts_ref->[0]."\n";
    }
    
    # Return either value or error string dependent on mode
    my $result = "";    # The return value
    if ($isTest) {
        # Any errors will be displayed in the Debug window on the EmailPlusTemplate record
        $result = $errorTags;
    }
    else {
        # This is what will be inserted into the EmailPlus notification message
        $result = $fieldValue;
    }
    
    EMP_DebugOut("END - result \= \<$result\>");
    return $result;
}