How to add params to all links in a mandrill template through API? - mandrill

I need to add some params to all links from a Mandrill template before sending.
For example, in the template there are anchors like <a href="http://google.com>click here</a>".
What I need is to add a string (set of params to every anchor), like this: <a href="http://google.com?param1=value1&param2=value2>click here</a>", dynamically
Is there a way to do it through the API? Something similar to X-MC-GoogleAnalyticsCampaign which adds the utm_campaign param.

Sure, you can use merge tags to do this. Your link would look something like this:
click here
You'd then want to pass the values for PARAM1 and PARAM2 in the SMTP headers, or in your API call.
For SMTP, you'd use the X-MC-MergeVars header. Here's more information on that specific header: http://help.mandrill.com/entries/21688056-Using-SMTP-Headers-to-customize-your-messages#mergetags
If you're using the API (messages/send or messages/send-template), you'd want to use the merge_vars or global_merge_vars parameters to set the values for PARAM1 and PARAM2 (merge_vars is for recipient-specific info, while global_merge_vars is for all recipients in that API call).
General overview on using merge tags to create dynamic content with Mandrill: http://help.mandrill.com/entries/21678522-How-do-I-use-merge-tags-to-add-dynamic-content-

Related

Query Parameters in URL from a Rails form

I have a filter sidebar that starts with a Rails form_tag and contains a range slider and a bunch of check_box_tag.
It posts and filters fine. It even persists on the next page as I render it with the checkbox values.
However, if you refresh the page, or send a link to someone, the filters are lost.
The only way I've seen how to do it is to use redirect_to and merge the params, but I'd rather not make a second call.
How can I pass all the options as query params?
As you're not creating anything I would recommend using GET requests with query string parameters. So the query can be shared with the url.
Url for your example image would be something like:
http://www.yourwebsite.com/?max_price=5
Which gives you a params[:max_price] in controller.

Generate a dynamic, traditional URL (i.e. not an Action/Controller route) using #Html.ActionLink

I need to create a dynamic tag with a url containing JSON values that will be posted to an external payment gateway. Eventually I want something like this:
Pay This Amount
So I figured I would do:
#Html.ActionLink("Pay This Amount", "https://xyz.com/PayNow?paymentData={'StoreID':'1964','Person':{'FirstName':'Joe','MiddleInitial':'A','LastName':'Smith'},'Item':{'1':{'Price':'250','Code':'TUITION'}}}")
But the resulting tag makes the URL in Action/Controller format:
MyWebSite/MyController/https://xyz.com/PayNow?paymentData={'StoreID':'1964','Person':{'FirstName':'Joe','MiddleInitial':'A','LastName':'Smith'},'Item':{'1':{'Price':'250','Code':'TUITION'}}}
...and of course it fails.
I want just a traditional URL not a route. I don't see an overload for a simple URL. Or is there another helper that I can use to create a non-MVC URL?
How do I do this? Thanks!
Thanks.
#Html.ActionLink is used to create an tag to a controller/action in your site. If you just want to create a link to another site just use plain ole HTML:
Pay Now
If you need to use properties from your model you can build the URL in code and then reference that in the tag:
#{
string url = "https://xyz.com?id=" + Model.Id;
}
Pay Now
or
Pay Now

grails, add only existing params from current url to pagination

guys!
I`d like to make 'clever pagination'. For example, if i already have params.category=Auto - i want it to be added to my params.
Of course, i can do smth like this :
<g:paginate total="${total}" max="10" maxsteps="5" params="[category: params.category,subcategory: params.subcategory]"/>
But if current params.subcategory is null - it will also be added to url ( ?subcategory=&category=Auto) . I don`t want to have 'subcategory=' in my params in such a case!
Also I can do it with string concatenations to create new url - but maybe grails have some cheats/mechanism to create new url without string concatenations?
Cheers, Dmitry.
There aren't any great solutions I can think of. You could try:
params="${[category: params.category,subcategory: params.subcategory].findAll {it.value} }"
Alternatively, provide your own custom tag that strips out null param values before delegating to the paginate tag.

Symfony/Routing: Using POST to Avoid Query Params in URL

I want to pass the id from one action to the next action, but I do not want it seen in the URL. Is there a way to hide it?
Using Symfony, I have created a sign-up done page whose URL should be /signup/done
When the form is processed, I want to redirect to the signupSuccess action and pass the recently created ID for future use. So I use...
$this->redirect('#signup_done?id=' . $sign_up->getId());
The routing is as follows:
signup_done:
url: /signup/done
param: { module: SignUp, action: signupDone }
I have avoided the :id at the end because I don't want it in the URL.
But the resulting URL is /signup/done?id=1
Just as an experiment, I tried putting this on a template.
<?php echo link_to('Sign-up again', '#signup_done?id=1', 'post=true') ?>
Even when using post, the query parameter appears in the URL.
The need is: I want to pass the id from one action to the next action, but I do not want it seen in the URL. Is there a way to hide it?
I set the id as a parameter in the request using $request->setParameter('id', $id) and it was available in the next action.
This kept the URL clean.
If you want to post, you need a form. Back in symfony 1.2 there were helpers that you could call and made you just that - but they were removed for the promotion of promoting good code.
Depending on how you want the 'Sign up again' text to look, you can either create a simple form and a submit button, or create a link, attach a click listener, and create a form there via JS, finally post it.
Any parameter that you pass to the route in url_for, link_to and such end up in the get parameters.

How to send extra parameters on a link/button_to_remote call?

Prototype's Ajax accepts a parameter called 'parameters' with an hash array for parameters (prototype doc) which would automatically be sent as GET or POST vars, but I could not find how to add items to that array using the Rails button_to_remote method.
I could just add the parameters to the URL sent to the method, but that feels hackish.. Is there a better solution out there?
I actually found the solution! You can pass parameters in the function using the :with option, like this:
<%=button_to_remote "+3", {:url =>task_path(#project, #story, task), :with=>"'actual=3'"}%>
The trick is that the value for :with is a javascript expression that should return a key-value pair in the URL format, like "key=value". That's why there's extra quotes around the value on the same above.
A function could also be used to pull the information from the page, if necessary:
:with=>"getValuesForPostbackFunction()"
The function will be evaluated before the form is submitted.
Using button_to_remote the only way to send parameters to the next action is putting them into the URI.
button_to_remote is intended as a functional equivalent of link_to_remote, which also has no other way of adding parameters.
If you need more fine-grained control, you need to build the full form and submit that to your action.
Add hidden input fields in the form that you're calling the button_to_remote on.
<input type="hidden" name="name" value="myValue">

Resources