Dynamic content in email templates

I have rails and am working on implementing something like the one in the picture enter image description here

My email template will have these tags. When sending a letter to the client, his information will be filled in the template. I found this link here , but no answer. I looked up and found this stone, however I can’t use it because it uses liquid patterns, and I couldn’t implement it because of the time limit.

I know that I can do everything to find {{first_name}}and replace the content whenever a tag appears, but I doubt that its an effective way to implement it.

Share your ideas and recommendations. Thanks in Advance :)

+6
2

noob , , . , , - :

class DynamicTemplateModel < ActiveRecord::Base

  def self.parse_template(template, attrs={})
    result = template
    attrs.each { |field, value| result.gsub!("{{#{field}}}", value) }
    # remove anything that resembles a field but did not match a known field name
    result.gsub!(/\{\{\.w+\}\}/, '')
    return result
  end

end

: DynamicTemplate.parse_template(body, details)

details = {first_name: user.first_name, last_name: user.last_name, company: user&.company&.name, email_address: user.email}

body = "Hi {{first_name}} {{last_name}}, Your company {{company}} is registered with us successfully"

parse_template , .

diofeher . .

, -. , .

+4

, Liquid , (http://www.kuwata-lab.com/erubis/).

:

ERB.new(your_template.gsub("{{", "<%=").gsub("}}", "%>")).result

{{ }}.

0

Source: https://habr.com/ru/post/1016754/


All Articles