Giter Club home page Giter Club logo

Comments (3)

mostafah avatar mostafah commented on June 2, 2024

I’m not sure I’ve understood this issue. You can already add both merge variables (global ones though, not per recipient) and template content data. What exact change are you expecting for this issue?

BTW, thanks for the kind words.

from mandrill.

owentran avatar owentran commented on June 2, 2024

Thanks for the quick reply.
I have a template in Mandrill with the following merge var and dynamic section.

Hello *|NAME|* also known as <span mc:edit="NAME"></span>

Example in README

tmplName := "hello-world"
email := "[email protected]"
name := "mostafah"
data := map[string]string{("NAME": name})
mandrill.NewMessageTo(email, name).SendTemplate(tmplName, data, true)

This will send and email with the content

Hello also known as mostafah

If you add the AddGlobalMergeVars, it will format the data for Merge Vars as well

// Same variable declaration as above but do the following
msg := mandrill.NewMessageTo(email, name)
msg.AddGlobalMergeVars(data)
result, err := msg.SendTemplate(tmplName, data, true)

Now the email will be

Hello mostafah also known as mostafah

I believe the issue is that SendTemplate just sends template data...

data.TemplateName = tmpl
data.TemplateConent = mapToVars(content)

While AddGlobalMegeVars adds the data to the the msg

msg.GlobalMergeVars = append(msg.GlobalMergeVars, mapToVars(data)...)

Thanks.

from mandrill.

mostafah avatar mostafah commented on June 2, 2024

Well, that’s by design. Mandrill accepts two kinds of data: merge variables and template data. You can send both with this package, but they are separate things. I can’t send what is passed for template data as merge variables too. That takes the ability to set different merge variables from people.

Mandrill’s API provides two different arrays for these, and the library does that too.

To tell it again in other words, Mandrill’s Send-Template function takes these (and other things) as JSON input:

{
    "template_name": "foo",
    "template_content": [
        {"name": "varname", "content": "value"},
        {"name": "varname", "content": "value"},
        …
    ],
    "message": {
        "global_merge_vars": [
            {"name": "varname", "content": "value"},
            {"name": "varname", "content": "value"},
            …
        ],
    }
}

You can set the first one with function SendTemplate and the second one with function AddGlobalMergeVars. Merging the two doesn’t make sense for other users.

from mandrill.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.