createLink not working in (mail) templates? - email

I have a Controller action and sending a mail in it with something like:
mailService.sendMail {
...
g.render(template: "mailtemplate")
}
in this template file is called _mailtemplate.gsp I use
linktext
But the output is http://action ... that's it! I would expect to have http://www.example.com/action. If I use the same createLink tag in a gsp which is not a template it's working (by the way, email is working fine and all the other stuff in this template is rendered well).
Have you any suggestions on that?

Probably you need absolute link:
linktext
Btw, you can also use ${} syntax there, like:
linktext

QUOTE: I must specify a serverURL in config file, but I want it dynamically
You can probably do as such:
config.groovy:
environments {
development {
grails.serverURL = "http://localhost:8080"
}
production {
grails.serverURL = "http://www.mywebsite.com"
}
}
Then in your service sending the email:
import org.codehaus.groovy.grails.commons.ConfigurationHolder
def baseURL = ConfigurationHolder.config.grails.serverURL
mailService.sendMail {
...
g.render(template: "mailtemplate", model:['baseURL':baseURL])
}
And at last in your link:
linktext
I hope this helps

Related

How to set global baseUrl for Axios in Gatsby?

I am building website using Gatsby and I am fetching some data from my backend. I want to set set global baseUrl for Axios. Normally I will do something like this:
import axios from "axios";
axios.defaults.baseURL = "API_ADDRESS";
But where should I put this in Gatsby to make it global?
in case someone else comes here, the suggestion of mohammed agboola is not accurate, using onInitialClientRender the base url will change to client side url when you refresh the page, in the same file gatsby-browser.js you should be using onClientEntry instead of onInitialClientRender :
export function onClientEntry() {
axios.defaults.baseURL = "YOUR_BASE_URL"
}
Create a gatsby-browser.js file in the root folder of your project, if you don't have one.
and use the lines of code below:
const axios = require("axios").default
exports.onInitialClientRender = () => {
axios.defaults.baseURL = "YOUR_BASE_URL_HERE"
}
The above lines of code set axios baseURL when Gatsby App is rendered to the browser. Hope this answers your question.

sendgrid substitutions not working

I'm just trying to set up a trial email for SendGrid, it's the first time I've used it so I'm sure this is simple, but I can't seem to get the placeholder data to replace.
I'm using NodeJS library like this:
sgMail.setApiKey(mailConfig.apiKey);
const msgConfig = {
to: email,
from: mailConfig.defaults.from,
templateId: mailConfig.templates.registrationConfirmation,
substitutions: {
'--displayName--': original.displayName,
'--companyName--': 'Hello world'
}
};
console.log('Sending: ', msgConfig);
// now send the registration confirmation email.
return sgMail.send(msgConfig).then(() => {
console.log('done.');
})
.catch((err) => {
console.error(JSON.stringify(err));
});
And in the template there's a text block that I added using the visual editor:
Hello --displayName--
We would love to take this opportunity to welcome you to the store.
from
--companyName--
However when I run the test to send the email, it sends the mail okay, but doesn't substitute the placeholders.
What am I missing here?
try changing 'substitutions' to 'dynamicTemplateData'. Looks like they changed the name in the new version.
how i figured it out:
https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/mail/USE_CASES.md
It is not clear in Sendgrid documentation, but I think it is missing this line:
sgMail.setSubstitutionWrappers('--', '--'); // Configure the substitution tag wrappers globally
Then remove dashes in substitutions object keys
Look at this link: Sendgrid
So, your code should be:
sgMail.setApiKey(mailConfig.apiKey);
// Configure the substitution tag wrappers globally
sgMail.setSubstitutionWrappers('--', '--');
const msgConfig = {
to: email,
from: mailConfig.defaults.from,
templateId: mailConfig.templates.registrationConfirmation,
substitutions: {
'displayName': original.displayName,
'companyName': 'Hello world'
}
};
...
I hope this helps you!
For anyone NOT using dynamic templates, use Sendgrid's helpers as described here: substitution use case
IMPORTANT: If using personalization helper, don't forget to set your setSubstitutionWrappers at the PERSONALIZATION level like so personalization.setSubstitutionWrappers(['%%', '%%']).
If not using personalization, just set it at the global helper:
import mailClient from '#sendgrid/mail';
mailClient.setSubstitutionWrappers('%%', '%%')
const msgConfig = {
to: email,
from: mailConfig.defaults.from,
templateId: mailConfig.templates.registrationConfirmation,
};
msgConfig.addSubstitution('%displayName%', 'Something to display');
It seems user given variables don’t work when you have the angle brackets <% ... %> around them, these are reserved for the <%body%> and <%subject%> tags.
So now you can make your template that might look something like this - %displayName%

Double registration form in moodle

I'm editing a site based on moodle, and i need to create a double registration form. The first is already set (for schools), i need to create another one for private user. What would be the best way to do it?
Would be worth to copy the main signup files (signup.php and signup_form.php) and then make changes there?
Really thanks
I think the best solution would be to create a new authentication plugin.
https://docs.moodle.org/dev/Authentication_plugins
Maybe copy the code from here /auth/email into /auth/newname - replacing email with newname in the code.
Possibly extend the class? so something like this in /auth/newname/auth.php
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/auth/email/auth.php');
class auth_plugin_newname extends auth_plugin_email {
...
function can_signup() {
return true;
}
...
Then copy /login/signup_form.php into /auth/newname/signup_form.php
The next bit I'm not too sure about but you will probably need to modify /login/signup.php
Around the lines
if (empty($CFG->registerauth)) {
print_error('notlocalisederrormessage', 'error', '', 'Sorry, you may not use this page.');
}
$authplugin = get_auth_plugin($CFG->registerauth);
Change to
if (optional_param('newname', false, PARAM_BOOL)) {
$authplugin = get_auth_plugin('newname');
} else {
if (empty($CFG->registerauth)) {
print_error('notlocalisederrormessage', 'error', '', 'Sorry, you may not use this page.');
}
$authplugin = get_auth_plugin($CFG->registerauth);
}
Then for private registrations use
http://www.yoursite.com/login/signup.php?newname=1
Replace 'newname' with the name of your new authentication plugin.

typo3 fe-manager how to get different admin emails

i have a question about fe-manager. In this extension it is possible to send a confirmation email to a admin. But it is always the same email. i like to send emails to various admins. for example: if the new user is from germany the receiving adress should be some#thing.de. if the new user is from switzerland the adress should be some#thing.ch.
any idea how to approach this?
any hints/solutions are more than welcome.
current state:
extension is created. i copied the finalCreate-Method from the AbstractController to my NewController. i changed the makeEmailArray() from:
Div::makeEmailArray(
$this->settings['new']['notifyAdmin'],
$this->settings['new']['email']['createAdminNotify']['receiver']['name']['value']
),
to:
Div::makeEmailArray('xxx#xxx.ch',
$this->settings['new']['email']['createAdminNotify']['receiver']['name']['value']
),
the ts setup.txt file is located in femanager_extended/Configuration/TypoScript/setup.txt
and contains the following code:
config.tx_extbase.objects {
In2\Femanager\Controller\NewController.className = Lbaumann\FemanagerExtended\Controller\NewController
}
is this the right approach?
There is no TypoScriptConfig for this behaiviour, but you can easily override the ControllerMethod and extend it with your needs.
Create your own extension like Vender "Vendor" (company/customername) and key "femanager_extended" with the extension_builder.
femanager_extended/Classes/Controller/NewController.php
<?php
namespace Vendor\FemanagerExtended\Controller;
class NewController extends \In2\Femanager\Controller\NewController
{
public function finalCreate($user, $action, $redirectByActionName, $login = true)
{
// own business logic
// replace the first Div::makeEmailArray...
// with your selected Admin-email-address
// see parent::finalCreate($user, $action, $redirectByActionName, $login);
}
}
femanager_extened/ext_typoscript_setup.txt
config.tx_extbase.objects {
In2\Femanager\Controller\NewController.className = Vendor\FemanagerExtended\Controller\NewController
}
I hope this will help you and i don´t forgot any settings.

portletURLFactory.create does not work in liferay VM

I'm trying to create a link in a Liferay template using Velocity.
My code is the following, based on several examples on the net:
#set ($plid = $getterUtil.getLong($request.get('theme-display').get('plid')))
#set ($u = $portletURLFactory.create($request,"1",$plid,"RENDER_PHASE"))
$u.setParameter("struts_action","/asset_publisher/applyForJob");
yyy
I get the plid value, but my URL will be just ending with $u, it seems that the $portletURLFactory.create() method is not properly interpreted.
Any ideas? Thank you!
Are you trying to do this inside Web Content Template? In that case it will not work because you do not have access to the real http request object. You need to create this link using javascript instead. Here is a code snippet.
<script type="text/javascript">
function createURL() {
AUI().ready('liferay-portlet-url', function(A) {
var renderURL = Liferay.PortletURL.createRenderURL();
renderURL.setParameter("struts_action","/asset_publisher/applyForJob");
renderURL.setPortletId("1");
renderURL.setPortletMode("view");
renderURL.setWindowState("normal");
window.location = renderURL.toString();
});
}
</script>
Go