For example, native Magento theme-frontend-blank\web\js\navigation-menu.js has such code:
$.widget('mage.navigationMenu', {
options: {
...
collapsableDropdownTemplate:
'<script type="text/x-magento-template">' +
'<li class="level0 level-top more parent">' +
'<div class="submenu">' +
'<ul><%= elems %></ul>' +
'</div>' +
'</li>' +
'</script>'
And then they do
this.collapsableDropdown = $(
mageTemplate(
this.options.collapsableDropdownTemplate,
{elems: this.elemsToCollapseClone}
)
);
Is it possible to do something like this
collapsableDropdownTemplate: getTemplate(some_relative_path_to_template) ?
instead of
collapsableDropdownTemplate:
'<script type="text/x-magento-template">' +
'<li class="level0 level-top more parent">' +
'<div class="submenu">' +
'<ul><%= elems %></ul>' +
'</div>' +
'</li>' +
'</script>'
My template is a little bit bigger and I want to allow frontend developers to modify it.
Related
I built out a script to automatically send out an email based on the results from the form. It was working great and would complete the function in about 10 seconds.
I switched to using GmailApp to send emails so that I can use aliases, however, now my function just hangs after completing the last step, which is assigning the "Email Sent" value and running SpreadsheetApp.flush().
Under the executions page, it shows the function is running upwards of 900+ seconds and has to be manually terminated.
Any thoughts? Appreciate the help!
function sendSurvey() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Test Sheet");
var startRow = 2;
var numRows = 100000;
var dataRange = sheet.getRange(startRow, 1, numRows, 100);
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var npsstatus = row[8];
var csm = row[9];
var emailSent = row[11];
var subject = 'Customer Renewal Survey';
var message = "<HTML><BODY>" +
'<h3>Looks like a customer may require your help!</h3>' + "<br>" +
'<b>Customer Contact: </b>' + " " + row[1] + "<br>" + "<br>" +
'<b>Dedicated CSM: </b>' + " " + row[9] + "<br>" + "<br>" +
'<b>Likelyhood to Recommend: </b>' + " " + row[3] + ' (' + row[8] + ')' + "<br>" + "<br>" +
'<b>What they need help with: </b>' + " " + row[4] + "<br>" + "<br>" +
'<b>Additional Comments: </b>' + " " + row[5] + "<br>" + "<br>" +
'<b>CSM Best Time to Connect: </b>' + " " + row[13] + "<br>" + "<br>" +
"<br>" + "<br>" +
'<img src="cid:image"> <br/>'+
"</BODY></HTML>";
var image = DriveApp.getFileById("");
var imageblob = image.getBlob();
var body = message.replace(/\<br\/\>/gi, '\n').replace(/(<([^>]+)>)/ig, "");
var aliases = GmailApp.getAliases();
Logger.log(aliases);
if (npsstatus == 'Detractor' && emailSent != 'Email Sent') {
GmailApp.sendEmail(primaryEmail, 'Test Survey', body, {htmlBody: message, 'from': aliases[0], name: 'Survey', inlineImages: {image: imageblob}});
sheet.getRange(startRow + i, 12).setValue('Email Sent');
}
SpreadsheetApp.flush();
}
}
I have this Play template, dynamicLink.scala.html...
#( urlWithQuotes: Html, id: Html, toClick: Html )
#uniqueId_With_Quotes() = {
Html("\"" + (#id) + "_" + scala.util.Random.nextInt.toString + "\"")
}
#defining(uniqueId_With_Quotes()) { uniqueID =>
<a id=#uniqueID class="dynamicLink" href=#urlWithQuotes> #toClick </a>
<script><!--Do stuff with dynamic link using jQuery--></script>
}
It generates a special link with some Javascript. I render this link like so...
#dynamicLink(
Html("#{routes.Controller.action()}"),
Html("MyID"),
Html("Click Me")
)
When I render it, I get...
<a id=
Html("\"" + (MyID) + "_" + scala.util.Random.nextInt.toString + "\"")
class="dynamicLink" href=#{routes.Controler.action()}> Click Me </a>
This is not what I want to render. I want to render this...
<a id="MyID_31734697" class="dynamicLink" href="/path/to/controller/action"> Click Me </a>
How do I make this HTML escape correctly?
* Take #2 - replacing Html params with String *
#(urlWithQuotes: String, id: String, toClickOn: String)
#uniqueId_With_Quotes() = {
Html("\"" + (#id) + "_" + scala.util.Random.nextInt.toString + "\"")
}
#defining(uniqueId_With_Quotes) { uniqueID =>
<a id=#uniqueID class="dynamicLink" href=#urlWithQuotes> #toClickOn </a>
...
}
With...
#dynamicLink2(
"#{routes.Controller.action()}",
"MyID",
"Click Me"
)
Renders...
<a id=
Html("\"" + (MyID) + "_" + scala.util.Random.nextInt.toString + "\"")
class="dynamicLink" href=#{routes.Controller.action()}> Click Me </a>
<script>
...
</script>
* Changing Html to String didn't work *
* Note that " #uniqueId_With_Quotes() " expands into " Html("\"" + (MyID) + "_" + scala.util.Random.nextInt.toString + "\"") ". I want it to actually execute string concatenation. *
Also, this should be obvious, but I want each link and the accompanying jquery to be rendered with an ID that is unique to that link and I don't want the controller to have to worry about assigning these unique id's. My way of doing that is by appending a random number to each id (although it might just be better for the view to have a count). I need to have this stateful behavior in the view because I need "dynamicLink" to be totally transparent to the controller.
Did you tried to use the variables as String types?
#( urlWithQuotes: String, id: String, toClick: String )
I find the solution. You have to pass a Call object.
#dynamicLink(
({routes.Controller.action()}),
"MyID",
"Click Me"
)
Pass those parameters into...
#(urlNoQuotes: Call, id: String = "", toClickOn: String = "")
#uniqueId_With_Quotes() = #{
Html("\"" + (id) + "_" + scala.util.Random.nextInt.toString + "\"")
}
#url() = #{
Html("\"" + urlNoQuotes + "\"")
}
#defining( url() ) { processedURL =>
#defining(uniqueId_With_Quotes()) { uniqueID =>
...
}
}
^ Now it works.
I know it's a beginner question and probably very easy but I can't get it to work. I have a map with 2 utfgrids which show an information about bicycle and hiking routes. It is based on this example:
http://bl.ocks.org/milkbread/6449317
It works fine but I would like to change it this way. When hoovering the existing infobox should show up but when clicking on the route the popup should show up in the place where I clicked (with the same information that shows up in the infobox).
I tried different ways to apply it but I always get an error. Here's a link to my working webiste and a part of the code responsible for the infobox window.
http://wojtas82.zrujnowane.pl/utf2.html#15/54.5027/18.4886/osm-rowerowe-piesze
And the code:
utfGrid2.on('mouseover', function(e){ info.update(e);}).on('mouseout', function(e){ info.update();})
utfGrid1.on('mouseover', function(e){ info.update(e);}).on('mouseout', function(e){ info.update();})
var info = L.control();
info.options.position = 'bottomleft';
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info'); // create a div with a class "info"
this.update();
return this._div;
};
info.update = function (props) {
this._div.innerHTML = (props ?
'<img src="img/' + props.data.route +'_'+ props.data.osmc_color +'_'+ props.data.osmc_background +'_'+ props.data.osmc_foreground + '.png" ><br /> ' + "<b>" + props.data.name + "</b><br />" + 'Długość: ' + (props.data.distance ? props.data.distance : '') + ' km' + "<br />" + 'Opis szlaku: ' + (props.data.description ? props.data.description : '') : '');
};
I will be very greatful for help.
Thank you very much.
Have you tried using
L.popup for your popup? Something like
utfGrid1.on('click', function(e) {
if (e.data) {
L.popup()
.setLatLng(e.latlng)
.setContent(e ? '<img src="img/' + e.data.route + '_' + e.data.osmc_color + '_' + e.data.osmc_background + '_' + e.data.osmc_foreground + '.png" ><br /> ' + "<b>" + e.data.name + "</b><br />" + 'Długość: ' + (e.data.distance ? e.data.distance : '') + ' km' + "<br />" + 'Opis szlaku: ' + (e.data.description ? e.data.description : '')).openOn(map);
}
});
I have a Salesforce Email Service which accepts only text attachments.
Everything works fine till someone sends an email from Outlook or Lotus Notes.
My class doesn't even recognize a text attachment when sent from Outlook and Lotus Notes.
After careful research I found out that the text attachments are sent with the MIME Format of text/csv when I send an email from Gmail and in case of Outlook/Lotus Notes the format is application/octet-stream.
Has anybody faced something similar and any suggestions to over come the situation?
Here is my Email Controller Class which is being used in the Email Service
global class CreativeDCoe_EmailHandler implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
System.debug('<<<<<< Starting Email Listener >>>>>>');
List<String> attInserted = new List<String>();
List<String> attNotInserted = new List<String>();
String csvBody = '';
String strAttachmentName = '';
String strEmailSubject = '';
String strProgramID = '';
Integer totalRecords = 0;
String strDebugger = 'Logs<br /><br />';
//Reading Email Subject Line to get the Program ID
strEmailSubject = email.subject;
strDebugger += 'Email Subject : <i>' + strEmailSubject + '</i><br />';
System.Debug('<<<<<<< Email Subject : ' + strEmailSubject + ' >>>>>>>');
//strProgramID = strEmailSubject.substring(strEmailSubject.indexOf(' : ') + 3, strEmailSubject.length()) ;
strProgramID = strEmailSubject;
strDebugger += 'Program ID : <i>' + strProgramID + '</i><br />';
System.Debug('<<<<<<< Program ID : ' + strProgramID + ' >>>>>>>');
String[] filelines = new String[]{};
List<Program_Assessment_PA__c> attPADataList = new List<Program_Assessment_PA__c>();
List<Data__c> fy;
Boolean flag = false;
if(email.textAttachments != null)
{
//List<User> usr = [SELECT ID, Name, Email FROM User WHERE Email =: email.fromAddress LIMIT 1];
//if(usr.size() > 0)
if(true)
{
//strDebugger += 'Email sent from : <i>' + usr[0].Name + ' (' + usr[0].Email + ')</i><br />';
//System.Debug('<<<<<<< ' + usr[0].Name + ' >>>>>>>');
try {
List<Program__c> program = [SELECT Name, ID, Program_Name__c FROM Program__c WHERE Name =: strProgramID ];
if (program.size() > 0)
{
strDebugger += 'Program found on records : <i>' + program[0].Name + ' (' + program[0].Program_Name__c + ')</i><br />';
System.Debug('<<<<<<< Email Attachments (TEXT) found. >>>>>>>');
strDebugger += 'Total Number of text attachments : <i>' + email.textAttachments.size() + '</i><br />';
fy = [SELECT Name, ID FROM Data__c WHERE Name =: String.valueOf(system.today().year()) LIMIT 1];
if(fy.size() == 0)
{
Data__c newFy = new Data__c (Name = String.valueOf(system.today().year()));
insert(newFy);
System.Debug('<<<<<<< FY Inserted. >>>>>>>');
fy[0] = newFY;
System.Debug('<<<<<<< FY : ' + fy[0].Name + ' >>>>>>>');
}
System.Debug('<<<<<<< Total number of Text Attachments : ' + email.textAttachments.size() + ' >>>>>>>');
for (integer j = 0 ; j < email.textAttachments.size() ; j++)
{
strAttachmentName = email.textAttachments[j].filename.trim();
strDebugger += '<br />Text attachment <i>' + (j + 1) + '</i> : <i>' + strAttachmentName + '</i><br />';
System.Debug('<<<<<<< ' + (j+1) + ' Attachment Name : ' + strAttachmentName + ' >>>>>>>');
system.debug('<<<<<<< Extension of file : ' + strAttachmentName.substring(strAttachmentName.length() - 4, strAttachmentName.length()) + ' >>>>>>>');
// checking if the file is a csv file
if((strAttachmentName.contains('.csv')) && (strAttachmentName.substring(strAttachmentName.length() - 4, strAttachmentName.length()) == '.csv'))
{
attPADataList.clear();
csvBody = email.textAttachments[j].body;
System.Debug('<<<<<<< Total characters in the CSV file : ' + csvBody.length() + ' >>>>>>>');
filelines = csvBody.split('\n');
strDebugger += 'Total data lines in the CSV file : <i>' + (filelines.size() - 1) + '</i><br /><br />';
System.Debug('<<<<<<< Total data lines in the CSV file : ' + (filelines.size() - 1) + ' >>>>>>>');
for (Integer i = 1;i < filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
strDebugger += 'Total input values for line <i> ' + i + ' </i>are : <i>' + inputvalues.size() + '</i><br />';
System.Debug('<<<<<<< Total input values are : ' + inputvalues.size() + ' >>>>>>>');
if(inputvalues.size() != 0)
{
Program_Assessment_PA__c newPALineItem = new Program_Assessment_PA__c();
System.Debug('<<<<<<< Line : ' + i + ' >>>>>>>');
System.Debug(filelines[i]);
newPALineItem.Fiscal_Year__c = fy[0].ID;
newPALineItem.Date__c = system.today();
newPALineItem.Program_ID__c = program[0].ID;
if(isNotNull(inputvalues[0])){
newPALineItem.Question_ID__c = inputvalues[0].trim();
flag = true;
}
if(isNotNull(inputvalues[1])){
newPALineItem.Objective__c = inputvalues[1].trim();
flag = true;
}
if(isNotNull(inputvalues[2])){
newPALineItem.Dimension__c = inputvalues[2].trim();
flag = true;
}
// there are some other columns
if(flag) {
System.Debug('<<<<<<< Line item number ' + i + ' added to list. >>>>>>>');
attPADataList.add(newPALineItem);
flag = false;
}
}
}
System.Debug('<<<<<<< Inserting ' + attPADataList.size() + ' records to the PA Object >>>>>>>');
totalRecords += attPADataList.size();
insert attPADataList;
attInserted.add(strAttachmentName);
}
else
{
attNotInserted.add(strAttachmentName);
}
}
strDebugger += '<br />Total CSV\'s inserted : <i>' + attInserted.size() + '</i><br />';
System.Debug('<<<<<<< Total CSV\'s inserted : ' + attInserted.size());
if(attInserted.size() > 0)
{
//confirmation email message to the sender and support
String strSuccessHtmlBody = 'Hi, <br /> The Email Listener has successfully inserted ' + totalRecords + ' records to the Program Assessment (PA) from the following CSV files : <br /><br /><b>' + attInserted + '</b><br /><br /> Sender\'s Email ID : ' + email.fromAddress + '<br /> Subject Line : ' + email.subject + '<br /><br /><br /> Thanks, <br /> Email Listener Service <br/><br/><br/>' + '<br /><br /><br />' + strDebugger ;
String strSuccessEmailSubject = 'DCOE E-Mail Listener : Success';
System.debug('<<<<<<< DCOE Email Listener SUCCESS >>>>>>> ');
sendEmail(email.fromAddress, strSuccessHtmlBody, strSuccessEmailSubject);
}
else
{
//Non CSV attachment email message to the sender and support
String strNonCSVHtmlBody = 'Hi, <br /> The Email Listener failed to insert records from the following attachment(s) : <br /><br /><b>' + attNotInserted + '</b><br /><br /> Only CSV files are allowed for data import. <br /> Please re try with correctly formatted CSV file. ' + '<br /><br /> Sender\'s Email ID : ' + email.fromAddress + '<br /> Subject Line : ' + email.subject + '<br /><br /><br /> Thanks, <br /> Email Listener Service' + '<br /><br /><br />' + strDebugger ;
String strNonCSVEmailSubject = 'DCOE E-Mail Listener : Error - Non CSV Attachment(s) are not Accepted';
System.debug('<<<<<<< DCOE Email Listener No CSV Attachment(s) Found >>>>>>> ');
sendEmail(email.fromAddress, strNonCSVHtmlBody, strNonCSVEmailSubject);
}
}
else
{
//No Program found email message to sender and support
String strNoProgramHtmlBody = 'Hi, <br /> The Email Listener failed to insert records through the attachment(s). <br /><br /> There was no Program with program ID \'<i>' + strProgramID + '\'</i> found.' + '<br /><br /> Sender\'s Email ID : ' + email.fromAddress + '<br /> Subject Line : ' + email.subject + '<br /><br /><br /> Thanks, <br /> Email Listener Service' + '<br /><br /><br />' + strDebugger ;
String strNoProgramEmailSubject = 'DCOE E-Mail Listener : Error - No Matching Program Found';
System.debug('<<<<<<< DCOE Email Listener No Program Found >>>>>>> ');
sendEmail(email.fromAddress, strNoProgramHtmlBody, strNoProgramEmailSubject);
}
}
catch (Exception e)
{
//exception email message to sender and support
String strErrorHtmlBody = 'Hi, <br /> The Email Listener failed to insert records from the CSV file ' + strAttachmentName + '.<br /><br /> Sender\'s Email ID : ' + email.fromAddress + '<br /> Subject Line : ' + email.subject + '<br />Following is the exception occured : ' + e + '<br />Please check paramenters like Subject and attach a correctly formatted CSV file before re-sending.<br />' + '<br /><br /><br /> Thanks, <br /> Email Listener Service' + '<br /><br /><br />' + strDebugger ;
String strErrorEmailSubject = 'DCOE E-Mail Listener : Error';
System.debug('<<<<<<< DCOE Email Listener Exception >>>>>>> ' + e);
sendEmail(email.fromAddress, strErrorHtmlBody, strErrorEmailSubject);
}
}
else
{
// Denial email message to sender and support
String strDeniedHtmlBody = 'Hi, <br /> You are not permissible to use this Email Listener service. <br /> No records were inserted from the CSV file ' + strAttachmentName + '.<br /><br /> Sender\'s Email ID : ' + email.fromAddress + '<br /> Subject Line : ' + email.subject + '<br /><br /><br /> Thanks, <br /> Email Listener Service' + '<br /><br /><br />' + strDebugger ;
String strDeniedEmailSubject = 'DCOE E-Mail Listener : Error - You are not allowed to create records.';
System.debug('<<<<<<< DCOE Email Listener Denied User for Entry of Records>>>>>>>');
sendEmail(email.fromAddress, strDeniedHtmlBody, strDeniedEmailSubject);
}
}
else
{
//No Attachments found email message to sender and support
String strNoAttachmentHtmlBody = 'Hi, <br /> The Email Listener failed to insert records through the attachment(s). <br /><br /> There were no text attachment(s) found on the email. <br /><br /> Sender\'s Email ID : ' + email.fromAddress + '<br /> Subject Line : ' + email.subject + '<br /><br /><br /> Thanks, <br /> Email Listener Service' + '<br /><br /><br />' + strDebugger ;
String strNoAttachmentEmailSubject = 'DCOE E-Mail Listener : Error - No Attachment(s) Found';
System.debug('<<<<<<< DCOE Email Listener No Attachment(s) Found >>>>>>> ');
sendEmail(email.fromAddress, strNoAttachmentHtmlBody, strNoAttachmentEmailSubject);
}
return result;
}
public void sendEmail(String strFromEmailAddress, String strHtmlBody, String strEmailSubject)
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String contactEmail = strFromEmailAddress;
System.debug(strHtmlBody);
mail.setToAddresses(new String[] {contactEmail} );
mail.setSubject(strEmailSubject);
mail.setHtmlBody(strHtmlBody);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
public Boolean isNotNull(String str) {
return (str != null && str != '');
}
}
I am trying to manually call the markdownify filter in a Jekyll plugin. Here is what I have:
module Jekyll
class ColumnBlock < Liquid::Block
include Jekyll::Filters
def initialize(tag_name, markup, tokens)
super
#col = markup
end
def render(context)
text = super
'<div class="col-md-' + #col + '">' + markdownify(text) + '</div>'
end
end
end
Liquid::Template.register_tag('column', Jekyll::ColumnBlock)
I get the following error: Liquid Exception: undefined method 'registers' for nil:NilClass
I am very new to Jekyll and Ruby. What do I have to include when I want to use the markdownify filter?
Why do not call directly the converter??
See the source code
def render(context)
text = super
site = context.registers[:site]
converter = site.getConverterImpl(Jekyll::Converters::Markdown)
'<div class="col-md-' + #col + '">' + converter.convert(text) + '</div>'
end
Update - getConverterImpl is deprecated in Jekyll 3, you should use find_converter_instance instead :
def render(context)
text = super
site = context.registers[:site]
converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
'<div class="col-md-' + #col + '">' + converter.convert(text) + '</div>'