Host host = hostWebAPI.getCurrentHost(request);
User user = APILocator.getUserAPI().getSystemUser();
...
HashMap<String, Object> parameters = new HashMap<>();
...
parameters.put("text", "text to insert");
parameters.put("emailTemplate", "/email/news.vtl");
...
EmailFactory.sendParameterizedEmail(parameters, null, host, user);
if(UtilMethods.isSet(templatePath)) {
idInode = APILocator.getIdentifierAPI().find(host, templatePath).getInode();
Template t = null;
try {
if(InodeUtils.isSet(idInode)) {
t = UtilMethods.getVelocityTemplate("live/" + idInode + "." + Config.getStringProperty("VELOCITY_HTMLPAGE_EXTENSION"));
} else {
t = UtilMethods.getVelocityTemplate(templatePath);
}
} catch (Exception var19) {
;
}
MY EMAIL TEMPLATE $text WORKS!!!
Djacomo,
I think I remember that not working for me as well. The odd thing is my own code is basically doing the same thing as the dotCMS code, but mine works. Since you are already coding Java. Write your own email method to utilize the template:
If you don’t have a request context available, you can get a basic context:
Nathan I. Keiter
|
Lead Network Applications Programmer
|
Benefits Advisory Council Member
|
I.D.E.A Council Member
Gettysburg College | Information Technology | DataSystems
Campus Box 2453 | 300 North Washington Street | Gettysburg, PA 17325
Phone: 717.337.6993
--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
dotcms+un...@googlegroups.com.
To post to this group, send email to dot...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/dotcms/a2d29b2b-1e25-4106-8cba-254a549b1fd5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
It is a page object. Of course velocity content of some sort is included on the page either directly as content or via a widget.
Any variables you want to have accessible to that page must be added to the velocity context manually via Java. You add them in key/object pairs, where the key becomes the velocity variable name with a $ in front. They are then accessible to velocity for the merge. During the merge the variables are replaced with the objects and any velocity scripting is run before returning the “rendered page” result string.
So velocityContext.put( “someJavaObject”, myJavaObject );
Is then available in velocity as $someJavaObject etc.
#if ( $someJavaObject.getSomeValue() == true )##
<b>$someJavaObject.getSomePropertyValue()</b>
#end##
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/b041d2c6-30d7-4b73-94c4-5a24ee6748e5%40googlegroups.com.
VelocityEngine velocityEngine = new VelocityEngine();
velocityEngine.init();
String inode = identifierAPI.find(host, "/email/email.html").getInode();
String languageId = "_" + APILocator.getLanguageAPI().getDefaultLanguage().getId();
log.info("Languageid " + languageId);
String pageExtension = Config.getStringProperty("VELOCITY_HTMLPAGE_EXTENTION", "dotpage");
String liveUrl = "live/" + inode + "." + pageExtension; // REMOVED languageid for "NumberFormatException"
log.info("Liveurl " +liveUrl);
Template template = UtilMethods.getVelocityTemplate(liveUrl);
log.info("Template " + template.getName());
Context velocityContext = VelocityUtil.getBasicContext();
log.info("Contesto " +velocityContext);
// velocityContext.put("host", host);
// velocityContext.put("user", user);
StringWriter stringWriter = new StringWriter();
template.merge(velocityContext, stringWriter);
String htmlBody = stringWriter.toString();
log.trace("HTML BODY " + htmlBody );
Included on that template page is a Simple Widget that does a #dotParse( ‘/some/path/someFile.vtl’ ) of a velocity file. I believe this keeps things better organized. Also as a plus you can easily upload changes via WebDAV if you put your velocity in as files in the virtual file system tree instead of obfuscating them as content objects - which forces edits to be done in the back-end UI and makes things harder to find in my opinion.
Also of note, the page uses a “blank template”, meaning the template source is just $body, nothing else.
You can see in the velocity widget source how I am accessing the objects I added to context, “host” and “user”.
Nathan I. Keiter
|
Lead Network Applications Programmer
|
Benefits Advisory Council Member
|
I.D.E.A Council Member
Gettysburg College | Information Technology | DataSystems
Campus Box 2453 | 300 North Washington Street | Gettysburg, PA 17325
Phone: 717.337.6993
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/89b0391b26574707a003f0322d92cca5%40exch13c.ms.gettysburg.edu.
Yeah, I forgot to mention language id is only required for dotCMS 3.x +
As for your error, can you provide more information?
Often a merge error is the result of a velocity code error.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/95ce03d7-79b8-4aad-8941-1a57e5e15c07%40googlegroups.com.
As a general rule, work your way up from simple to complex until you encounter an error. Then the cause will become apparent. So maybe start with a plain text template with no velocity on it? Also I’m not sure what if any permissions requirements there are. I don’t think there are any, but I’m not sure. The template page should at least be published.
Nathan I. Keiter
|
Lead Network Applications Programmer
|
Benefits Advisory Council Member
|
I.D.E.A Council Member
Gettysburg College | Information Technology | DataSystems
Campus Box 2453 | 300 North Washington Street | Gettysburg, PA 17325
Phone: 717.337.6993
From: dot...@googlegroups.com [mailto:dot...@googlegroups.com] On Behalf Of Nathan Keiter
Sent: Wednesday, July 26, 2017 10:10 AM
To: dot...@googlegroups.com
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/5a08009ff4874a289d745c17fd382fdd%40exch13c.ms.gettysburg.edu.
##IMPORTANT
#parse ("preprocess.vl")
##IMPORTANT
<!DOCTYPE html>
<html lang="en">
<!--<![endif]-->
<head>
</head>
<body>
<h1> EMAIL THEME </h1>
<div>
#set ($mainColumn = $dotThemeLayout.body)
#if ($mainColumn.rows)
#set($count = 0)
#foreach($row in $mainColumn.rows)
#foreach($column in $row.columns)
<div class="col-sm-12">
$render.eval($column.draw())
</div>
#end
#end
#end
</div>
</body>
</html>
##IMPORTANT
#parse ("postprocess.vl")
##IMPORTANT
HELLO WORKD
Did you add $dotThemeLayout to the context in Java? If not that object will be null. I’m not sure where to fetch that from, perhaps a dotCMS API call in Java?
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/c600d21d-9ab5-4742-b3e2-21bf94206afe%40googlegroups.com.
Also, $render may need to be added to context. If you don’t explicitly add an object to context, it won’t be there.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/192937c803824dc3828e6912a7da2ee3%40exch13c.ms.gettysburg.edu.
You’ll need to build a basic template from scratch. Don’t use template designer.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/82b56af0-25e6-4f6c-9925-3d18c5435cc4%40googlegroups.com.
No problem. Glad I could assist you.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/3b83162d-043e-4df7-b4f4-5c91c0e3a5d7%40googlegroups.com.