HandlebarJS global counter - handlebars.js

I want to create a global counter which will get replaced with next value everytime it is used e.g. {{Counter}} And if I use as below in template
This is line {{Counter}}
This is line {{Counter}}
This is line {{Counter}}
This is line {{Counter}}
Then is shall render as
This is line 1
This is line 2
This is line 3
This is line 4
Is this possible through handlebarJS

You may use a HandlebarsHelper to achieve that.
var temp = 1;
Handlebars.registerHelper('Counter', function() {
return temp++;
});
And your Handlebars template be,
This is line {{Counter}}
This is line {{Counter}}
This is line {{Counter}}
This is line {{Counter}}
Which outputs
This is line 1
This is line 2
This is line 3
This is line 4
Tested using - http://tryhandlebarsjs.com/
Hope this helps.

Related

DocXtemplater multiple tags on a single line behavior

I am replacing an old program for template-merging with docxtemplater and am trying to recreate the old programs prefix functionality.
I want the line removed if all prefixed tags ({$tag}) on that line are undefined.
The issue being that if all the tags on that line are undefined docxtemplater still creates a blank line.
All the examples I have found online tend to reference inverted-sections or rawtags, which both seem to be designed for a single tag per line opposed to multiple tags side by side.
I have looked into using rawtags and writing a custom-parser / nullGetter. However I am still none the wiser to removing the blank line.
I am using:
const options = {
paragraphLoop: true,
linebreaks: false,
parser: function(tag) {
return {
get(scope, context) {
console.log(tag);
console.log(scope);
console.log(context);
if (tag[0] == "$") {
tag = tag.substr(1); // needs to then remove line break
}
return scope[tag];
}
}
},
nullGetter: function nullGetter(part, scopeManager) {
if (!part.module) {
return "";
}
if (part.module === "rawxml") {
return "";
}
return "";
}
};
doc = new Docxtemplater(zip, options);
The prefix in the program I am replacing acts as follows:
data:
existingtag: EXISTINGTAG
Template.docx:
1 text above
{$existingtag}{$nonexistingtag}
text below
2 text above
{$existingtag}{$existingtag}
text below
3 text above
{$nonexistingtag}{$nonexistingtag}
text below
old program produced (What I want to produce)
1 text above
EXISTINGTAG
text below
2 text above
EXISTINGTAGEXISTINGTAG
text below
3 text above
text below
my docxtemplater produces (extra line in example 3):
1 text above
EXISTINGTAG
text below
2 text above
EXISTINGTAGEXISTINGTAG
text below
3 text above
text below
I'm the creator of docxtemplater and I don't think that there is a way to do what you want to achieve without taking a lot of time to handle this case.
The problem is that the tags such as :
{xxx}{yyy}
have access only to the text that they are in, but they cannot have any effect ouside of that text, so it is not possible to remove a paragraph conditionnally.
There is one tag that has access to the whole paragraph, that is the raw xml tag, prefixed by a "#", like this :
{#raw}
It is used to add rawXML and if the raw value is an empty string, than that paragraph will be removed.
Edit : I have actually worked on a module back in the time to achieve quite similar functionnality, it is a paid module : https://docxtemplater.com/modules/paragraph-placeholder/

How to Preserve White Space and line breaks in Django?

I am making a project where I want to display a user's code. I am using Django's forms. But when I post that form, the form doesn't preserve the white space and the line breaks.
Can you please help me?
# this is my form
class VigenereCipherDiscussForm(forms.ModelForm):
class Meta:
model = VigenereCipherDiscuss
fields = ['text', 'share']
widgets = {
"text": forms.Textarea(attrs={"class":"form-control", "rows":4}),
"share": forms.Textarea(attrs={"class":"form-control", "rows":5, "placeholder": "Put in your cipher text or code in here to share with others"})
}
# (stackoverflow preserves the line breaks, the "class Meta" is indented nicely)
If i have this code:
x = 2
if x == 2:
return "2"
else:
return None
# I want this code to be outputted in the form the way it is right now!
But django gives me
x=2 if x==2: return "2" else return None
Use linebreak
change your code to:
x=2\nif x==2:\nreturn "2"\nelse:\nreturn None
and in template:
{{ value|linebreaks }}
you can use tinymce to create a user's code.it will save it in html.
and in your .html add this:{{ value|linebreaks|safe }}
the tinymce Like this:

How to set color, width and draw dashed line simultaneously for javafx line?

I have to draw multiple lines using javafx line chart. Since one line can overlap other lines. I want to use dashed line or line with different thickness to represent each line.
Below is my code snippet:-
for (XYChart.Series<Number, Number> s : chart.getData()) {
// Used for Line color
if (("Current Threshold").equals(s.getName())) {
s.getNode().setStyle(" -fx-stroke-width: 10; ");
s.getNode().setStyle("-fx-stroke: #00FF00; ");
s.getNode().setStyle("-fx-stroke-dash-array: 2 12 12 2; ");
}
else if(some condition)
{
// Some other condition to draw other lines
}
}
where chart is instance of LineChart.
Node.setStyle() methods override each other. I am unable to set multiple style together. Last style persists and others are overridden. ie for above sequence, dashed line is drawn. I am using css styles in java code.
Is there any way to apply multiple style, without overriding others.
Thanks
Node.setStyle() is, as the name should suggest, a setter method for the style attribute of a JavaFX Node.
By calling this method three times in a row, only the last invocation has an effect as the previous ones get overwritten.
So if you want to apply all three styles you should write:
node.setStyle("-fx-stroke-width: 10; -fx-stroke: #00FF00; -fx-stroke-dash-array: 2 12 12 2;");
Or even better, use a CSS File, see this answer for further reference: JavaFX Text styling for dynamic objects

how to change the text inside a markerclusters icon?

reference : http://code.google.com/p/google-maps-utility-library-v3/source/browse/trunk/markerclusterer/src/markerclusterer.js?r=110
on line 915 I am trying
this.div_.innerHTML = sums.text + "some additional info";
but it doesnt reflect the additional text?
I tried doing what you showed, changing the innerHTML, on version 2.0.9 of the clusterer. (line 244). It adds the static text to the cluster icon.
http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.9/src/markerclusterer.js

Subclassing a UILabel, Given a Warning

I have the following at the top of one of my UIViewControllers.m:
#implementation UILabel (Custom)
-(void)setTitleLabelColor
{
UIColor *titleColor = [UIColor colorWithRed:1 green:0.90196 blue:0 alpha:1.0];
self.textColor = titleColor;
}
#end
I basically want to have a method that makes the text color to yellow.
When I call that function, it always gives me a warning, saying the UILabel might not respond to it, but it works fine.
How can I get rid of the warnings?
You should also declare this in your header (.h) file. For example,
#interface UILabel (Custom)
-(void)setTitleLabelColor;
#end
Then #import this from another file when you want to use that method.

Resources