lib/txbr/template.rb
# Designed to replace special Braze variables like {{campaign.${api_id}}}
# and ${first_name}, which Liquid can't natively handle. If the variable
# exists in the given variables hash, replace it with the value directly.
# Otherwise, transform the var into something Liquid-friendly so it
# doesn't jam up the parser.
Designed to replace special Braze variables like {{campaign.${api_id}}}
and ${first_name}, which Liquid can't natively handle. If the variable
exists in the given variables hash, replace it with the value directly.
Otherwise, transform the var into something Liquid-friendly so it
doesn't jam up the parser.
Designed to replace special Braze variables like {{ campaign . $ { api_id }}} and $ { first_name } which Liquid can ' t natively handle . If the variable exists in the given variables hash replace it with the value directly . Otherwise transform the var into something Liquid - friendly so it doesn ' t jam up the parser .
def prerender(source, variables)
      source.gsub(/(?:\{\s*\{\s*)?(?:[\w\-\_\.\[\]]+\.)?\$\{\s*[\w\-\.\[\]]+\s*\}?\s*(?:\}?\s*\})?/) do |orig|
        plain = orig.sub(/\A\{\{/, '').sub(/\}\}\z/, '')
        result = if val = variables[plain]
          "\"#{val}\""
        else
          normalize_braze_var(orig)
        end
        if orig.tr(' ', '').start_with?('{{')
          result = "{{#{result}"
        end
        if orig.tr(' ', '').end_with?('}}')
          result << '}}'
        end
        result
      end
    end
def prerender ( source , variables ) source . gsub ( / (?: \{ \s * \{ \s *)?(?:[ \w \- \_ \. \[ \] ]+ \. )? \$ \{ \s *[ \w \- \. \[ \] ]+ \s * \} ? \s *(?: \} ? \s * \} )? / ) do | orig | plain = orig . sub ( / \A \{ \{ / , '' ) . sub ( / \} \} \z / , '' ) result = if val = variables [ plain ] "\"#{val}\"" else normalize_braze_var ( orig ) end if orig . tr ( ' ' , '' ) . start_with? ( '{{' ) result = "{{#{result}" end if orig . tr ( ' ' , '' ) . end_with? ( '}}' ) result << '}}' end result end end
Designed to replace special Braze variables like {{campaign.${api_id}}}
and ${first_name}, which Liquid can't natively handle.
Designed to replace special Braze variables like {{ campaign . $ { api_id }}} and $ { first_name } which Liquid can ' t natively handle .
source
<not_specific>
variables
<not_specific>