I'm a beginner in Meteor and i would like to send an invitation link to a dynamic generated page in my app with iron:router.
Meteor.methods({
'sendEmail': function(to) {
this.unblock();
SSR.compileTemplate( 'emailText', Assets.getText( 'html-email.html' ) );
Template.emailText.helpers({
link: function () {
return Router.current().route.path(this);;
}
});
Email.send({
to:to,
from: 'no-reply#whatever.xyz',
subject:'xyz wants to invite you ',
html: SSR.render('emailText')
});
}})
}
The Problem is that i dont get the url of the site in my html-email.html. There i got
Link to invitation
What am i doing wrong?
Your method is a server method (SSR). Router.current() is a client method and cannot return anything server side. The solution is to pass the url as a parameter. Call your method that way :
Meteor.call( 'sendEmail', email, url, ... )
Then your method will be :
'sendEmail': function( to, url ) {...
Looking at your code I would say you mix up server side methods and client side template helpers.
What do you want to achieve? Want the current route where the user is located in your site to be included in the mail? Then, send the url as an extra parameter in your sendEmail method like fabien suggested.
If the link is a static path that you use as a link to some landing page, I suggest to get that path from settings.json.
Either way, your problem is rendering an email with some link in it. You can pass an object as second parameter to SSR.render.
Here is how you could solve this:
Meteor.methods({
'sendEmail': function(to) {
this.unblock();
var linkInMail = 'htpp://some_url/etc?etc'; // Fill this value, see my remark above
var templateName = 'emailText';
SSR.compileTemplate(templateName, Assets.getText( 'html-email.html' ) );
var renderedContent = SSR.render(templateName, {link: linkInMail}); // This your missing part
Email.send({
to:to,
from: 'no-reply#whatever.xyz',
subject:'xyz wants to invite you ',
html: renderedContent
});
}})
}
Related
Our company has multiple brands and each brand has its own host name, but they are all part of the same site. We can let customers share baskets and other session information when they switch between brands via a redirect link using URLUtils.sessionRedirect.
But URLUtils is not available in content assets. Is it possible to form a session redirect link in content asset keeping all the session information?
Thanks in advance.
You can include dynamic content in Content Assets with the $include('Controller-Name', 'name1', 'value1', 'name2', 'value2', ...)$ syntax. See the MarkupText Class Documentation for more info on that syntax. The 'name1' and 'value1' parameters are mapped as query string attributes eg: Controller-Name?name1=value1&name2=value2
Create a controller that outputs the session redirect link you need, and call it via that syntax like: $include(Util-RenderSessionLink, 'siteID', 'foo')$
The controller would need to use a response Content-Type header of text/plain or something like that so that nothing is injected into the response. (eg: Storefront toolkit or tracking tags) For example:
response.setContentType('text/plain');
Alternatively, you could process the content asset for some sorts of keys that you perform find & replace operations on. For example, the following code does a find & replace on a Content Asset's body content for the key: '%%SessionLink%%'.
var ContentMgr = require('dw/content/ContentMgr');
var URLUtils = require('dw/web/URLUtils');
if (!empty(content) {
var content = ContentMgr.getContent('my-content-id');
var contentOut = "";
var viewData = {};
contentOut = content.custom.body.getMarkup()
.replace('%%SessionLink%%', URLUtils.sessionRedirect(...));
viewData.content = contentOut;
// then output your `pdict.content` key within a template with the appropriate encoding
}
If anybody else is running into this, we added a bit of client-side javascript that pickups up all outbound links and if it's one of our domains it sends them through a session redirect. This way we don't need content managers to fix very link between domains:
var domains = ["domaina.com", "domainb.com", "domainc.com"]
var sessionRedirectBase = '/s/Our-Site/dw/shared_session_redirect';
$(document).on("click.crossSite", "a", (e) => {
const href = $(e.currentTarget).attr("href");
if (href) { //does the link have a href
if (href.match(/^(http(s)?:)?\/\//)) { //is href an absolute url
const url = new URL(href);
if (url.hostname != window.location.hostname && domains.indexOf(url.hostname) > -1) { //is hostname not the current one and part of the domains array
e.preventDefault();
const sessionRedirect = `${sessionRedirectBase}?url=${encodeURIComponent(href)}`
window.location = sessionRedirect;
}
}
}
});
I have a Template in client
<template name="sendThis">
<img src="logo.png"><br>
<h3>Welcome to Meteor NewBie</h3>
Dear {{name}},
<p>You received this Email because you have subscribed to http://www.example.com</p>
</template>
I would like to send this Template(sendThis) as HTML body in my Email to subscribers.
I am using Mailgun as my Email Client. What are the steps I should take to make this happen as a subscriber clicks a button with an id "subscribe".
PS: I have multiple helpers in this template, multiple in the sense more than 20.
Thanks in advance.
Mahesh B.
One way to solve this is to use Blaze.toHTMLWithData to render your template (with a context) to an HTML string. You can then call a method on your server which emails the user with the appropriate subject and address. Here's an example:
client
var sendSignupEmail = function() {
// This assumes this first email address is the one you want.
// In some cases you may want the first verified email, but not
// during signup.
var address = Meteor.user().emails[0].address;
var subject = 'Thanks for signing up!';
// Here I used username - replace this with the appropriate data
// like Meteor.user().profile.firstName or something.
var body = Blaze.toHTMLWithData(Template.sendThis, {
name: Meteor.user().username
});
Meteor.call('sendEmail', address, subject, body);
};
server
Meteor.methods({
sendEmail: function(to, subject, html) {
check([to, subject, html], [String]);
this.unblock();
return Email.send({
to: to,
from: 'something#example.com',
subject: subject,
html: html
});
}
});
Also make sure your MAIL_URL environment variable has been defined.
I am using sailsjs v0.10.5.
I am trying to redirect to login after verifying user email and update the database before redirect.
I am using redirection in my update callback. But it sending the error after updating the database
'Cant send headers after they are sent'.
The following is the code am using for redirection:
verifyEmail: function(req, res){
var userId = req.param('userId');
User.update({id: userId},{isVerified: true}).exec(function(err, user) {
if (!err) {
req.flash('error', 'Your email is verified please login');
res.redirect('/login'); }else { return res.send(user, 400); }
});
Update waterline function is asynchronous, are you sure there isnt some res method later in the scope that may be fired before?
Its recommended to use return res.* for so-called "terminal methods" see http://sailsjs.org/#/documentation/reference/res/res.forbidden.html?q=notes
Getting blank values for title and description in serveResource method.Is this the right way to send the parameters from io request?
After inserting blank values in database I have to reload the page to see the inserted values?So io-request is not ajax request?
<aui:script use="aui-base">
A.one('#<portlet:namespace/>save').on('click', function(event) {
var A = AUI();
var title=A.one('#<portlet:namespace/>title').val();
alert(title);
var description=A.one('#<portlet:namespace/>description');
var url = '<%= newJob.toString() %>';
A.io.request(
url,
{
method:'POST',
data: {
<portlet:namespace />title: title,
<portlet:namespace />description: description,
},
}
['aui-io-deprecated']
);
Liferay.Util.getOpener().<portlet:namespace/>closePopup('<portlet:namespace/>dialog');
});
AUI's io request is ajax request only.
You can get parameters in serveResource method using code below:
ParamUtil.get(resourceRequest, "NAMEOFPARAMETER");
Modify your javascript function and provide data attribute as below:
data: {
'<portlet:namespace />title': title,
'<portlet:namespace />description': description,
}
I assume both title and description are textfields. If so, description is missing a .val() call, or more appropriately, .get('value'). I didn't use a dialog/modal in my source, but the overall approach should be the same.
<script>
AUI().use('aui-base', 'aui-io-request', function(A){
A.one('#<portlet:namespace />save').on('click', function(event) {
var title= A.one('#<portlet:namespace />title').get('value');
var description=A.one('#<portlet:namespace />description').get('value');
var url = '<%=myResourceURL.toString()%>';
A.io.request(url,
{
method:'POST',
data: {
title: title,
description: description,
},
});
});
});
</script>
I'm still relatively new to Liferay and have had trouble with this as well. I've noticed that the data parameters are not in the parametersMap of the default ResourceRequest, as you have stated. Out of curiosity, I decided to use
UploadPortletRequest req = PortalUtil.getUploadPortletRequest(resourceRequest);
in the serveResource method and check it's parametersMap. The title and description parameters are available therein. I'm still learning where and how to access data from Liferay objects, but it would seem that for the UploadPortletRequest to have the data, it would be plucked from somewhere within the default ResourceRequest ... where still remains elusive to me.
After inserting blank values in database I have to reload the page to see the inserted values?
You have to reload the page because a resource action does not trigger a page refresh. If you are manipulating data that you want reflected in some other "view" you'll need to configure the appropriate communication or use one of the other available url types that does trigger the doView method of your other "view".
i can navigate to
https://www.facebook.com/plugins/likebox.php?id=20531316728 via my browser
but cant use jQ $.get , (not working with the specific url)
url='https://www.facebook.com/plugins/likebox.php?id=20531316728&width=292&height=258&colorscheme=dark&show_faces=true&border_color&stream=false&header=false';
$.get(url, function(data){alert(data);} );
can i use any method to fetch the url (js is preferred ) ? any idea?
Simple, You cannot make cross domain ajax calls.
There are 2 options:
1) Try with JSONP Read - http://api.jquery.com/jQuery.getJSON/
2) Make an ajax call to your site URL where you can use CURL to facebook URL to get the data.
we could not access the cross domain data with ajax request
$.get("your_cross_domain_url",function(response)
{
});
So, you have to use a local file to accessing the cross domain data.
var content="your_url";
var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&##\/%?=~_|!:,.;]*[-A-Z0-9+&##\/%=~_|])/ig;
// Filtering URL from the content using regular expressions
var url= content.match(urlRegex);
if(url.length>0)
{
// Getting cross domain data
$.get("urlget.php?url="+url,function(response)
{
// do your stuff
});
and the urlget.php file should be like this
<?php
if($_GET['url'])
{
$url=$_GET['url'];
echo file_get_contents($url);//loading the URL data.
}
?>