class Crm::TemplateSet

TemplateSet represents the JustRelate WebCRM template set singleton. The templates of the {.singleton template set singleton} can be used to render customized text, e.g. a mailing greeting or a password request email body (password_request_email_body).

JustRelate WebCRM uses the {liquidmarkup.org/ Liquid template engine} for evaluating the templates. @api public

Public Class Methods

path() click to toggle source
# File lib/crm/template_set.rb, line 13
def self.path
  resource_name
end
singleton() click to toggle source

Returns the template set singleton. @return [TemplateSet] @api public

# File lib/crm/template_set.rb, line 20
def self.singleton
  new({}).reload
end

Public Instance Methods

render_preview(templates: {}, context: {}) click to toggle source

Renders a preview of the template set using the specified context items. This is for testing your (future) templates.

  • All templates contained in the set are rendered.

  • You may temporally add any number of templates to the set (just for the purpose of rendering).

  • Pass as context items all the instances (e.g. contact, acticity) for which the templates should be rendered.

Templates have access to the context items. You can use the following keys to represent context items:

  • account

  • contact

  • activity

  • mailing

  • event

The keys expect an ID as input. For example, {"account" => "23"} allows the template to access account.name of the account with the ID 23.

@example

contact.first_name
# => 'Michael'

template_set.templates['digest_email_subject']
# => 'Summary for {{contact.first_name}}'

template_set.render_preview(
  templates: { greeting: 'Dear {{contact.first_name}}, {{foo}}' },
  context: {contact: contact.id, foo: 'welcome!'}
)
# => {
#  ...
#  'digest_email_subject' => 'Summary for Michael',
#  'greeting' => 'Dear Michael, welcome!',
#  ...
# }

@param templates [Hash{String => String}]

the set of additional or temporary replacement templates to render.

@param context [Hash{String => String}] the context items of the preview. @return [Hash{String => String}] the processed templates. @api public

# File lib/crm/template_set.rb, line 74
def render_preview(templates: {}, context: {})
  Core::RestApi.instance.post("#{path}/render_preview", {
    'templates' => templates,
    'context' => context,
  })
end
update(attributes) click to toggle source

Updates the attributes of this template set. See {Core::Mixins::Modifiable#update Modifiable#update} for details. @return [self] the updated template set singleton. @api public

# File lib/crm/template_set.rb, line 28
def update(attributes)
  load_attributes(
      Core::RestApi.instance.put(path, attributes, if_match_header))
end