I can compare basic values with
<#if myvar=="value">do something..</#if>
But it doesn't support lists.
I didn't find any 'compare' like function in the documentation : https://freemarker.apache.org/docs/ref_builtins_sequence.html
It doesn't have such functionality (as of 2.3.29). You need to write a #function for it, if you really need to do this inside the template.
Related
I have a bit of a problem with internationalization in Symfony 1.4. For example let's say we have a word 'mois' which in French language means 'month' and also 'months'. So when I'm using i18n extract, I'm getting back only one option - mois, but I need to translate it either 'month' or 'months' depending on a situation. How can I get xml with two options?
I know about format_number_choice method, which gives me a good possibility to work with translations depending on value, but is there maybe some better way to extract that data without using this method?
format_number_choice is your best option. It was created exactly for this purpose: dealing with translating plural words. To get XML with two options, you would use the function as follows:
format_number_choice('[1]%1% mois|(1,12]%1% mois', array('%1%' => $monthCount), $monthCount)
And your XML would look like:
<trans-unit id="3">
<source>[1]%1% mois|(1,12]%1% mois</source>
<target>[1]%1% month|(1,12]%1% months</target>
</trans-unit>
This is the best way to extract the data you need in Symfony 1.4.
I was just wondering while reading my textbook how someone could write string-downcase for beginners in scheme? Thank so much!
I know how to do it using map but I was wondering if there was a more basic way to do it so that beginners to scheme can understand without knowing what map does. Thanks!
This time I'll write the general idea of the algorithm, you should know by now how to write this up using a template:
Transform the string to a list of characters, using string->list
Iterate over the list, and transform each character to lowercase using char-downcase
Build a new list with the newly transformed characters
Finally, transform back the resulting list using list->string
Basically we're mapping over the characters in the string. There are several fancy ways to do this, for instance using sequences, or map, etc. but for now, I believe is better that we stick to the basics and learn how to do this from scratch.
I have a question for Alfresco Community v4.0.0
I create content rule,
select execute script,
and in the script call processTemplate(ScriptNode template, array args)
How do I get an array into template? Args contains only key - value (String).
Thanks in advance for any advice or help
I think you're getting something like "Expected extended hash. args.array evaluated instead to freemarker.template.SimpleScalar", am I right?
If so, I'm afraid you can not get this working with scripts called from content rules, because there are no wrappers for complex datatypes, so this is the reason only String (and other scalars) is accepted.
You have two choices:
Alter alfresco code, which wraps objects and sends them into processTemplate() and build whole system (maybe more info on this you can find in my older blogpost)
Put an array into processTemplate() and in template read it like a string and then parse it - arrays looks like [val1,val2,val3], so refer to freemarker documentation for string functions and do something like this (ugly, but fast solution):
<#list args.array?split(",") as value>
hereRemoveFirstAndLastSquareBracketFrom(${value});
</#list>
Edit: If anyone interested, I just raised a bug in Alfresco JIRA
I'm currently working with JMeter in order to stress test one of our systems before release. Through this, I need to simulate users clicking links on the webpage presented to them. I've decided to extract theese links with an XPath Post-Processor.
Here's my problem:
I have an a XPath expression that looks something like this:
//div[#data-attrib="foo"]//a//#href
However I need to extract a specific child for each thread (user). I want to do something like this:
//div[#data-attrib="foo"]//a[position()=n]//#href
(n being the current index)
My question:
Is there a way to make this query work, so that I'm able to extract a new index of the expression for each thread?
Also, as I mentioned, I'm using JMeter. JMeter creates a variable for each of the resulting nodes, of an XPath query. However it names them as "VarName_n", and doesn't store them as a traditional array. Does anyone know how I can dynamicaly pick one of theese variables, if possible? This would also solve my problem.
Thanks in advance :)
EDIT:
Nested variables are apparently not supported, so in order to dynamically refer to variables that are named "VarName_1", VarName_2" and so forth, this can be used:
${__BeanShell(vars.get("VarName_${n}"))}
Where "n" is an integer. So if n == 1, this will get the value of the variable named "VarName_1".
If the "n" integer changes during a single thread, the ForEach controller is designed specifically for this purpose.
For the first question -- use:
(//div[#data-attrib="foo"]//a)[position()=$n]/#href
where $n must be substituted with a specific integer.
Here we also assume that //div[#data-attrib="foo"] selects a single div element.
Do note that the XPath pseudo-operator // typically result in very slow evaluation (a complete sub-tree is searched) and also in other confusing problems ( this is why the brackets are needed in the above expression).
It is recommended to avoid using // whenever the structure of the document is known and a complete, concrete path can be specified.
As for the second question, it is not clear. Please, provide an example.
I was going to use yaml because it has great feature called merge! ("<<" key)
And I'm using 'yaml-cpp' for parser since i'm working on cpp.
But! yaml-cpp does not support merge. What can I do for alternatives?
Other scripts, other parser, other way to parse or whatever is good if I can use merge feature.
BUT I don't need to merge more than one object. I just need define something and create another object inheritd from the first one and override some values. That it.
Thanks for reading.
If you're unable to wait and need merges, you can follow the suggestion by "barma" on the yaml-cpp issue: http://code.google.com/p/yaml-cpp/issues/detail?id=41#c12
The change is to insert the lines below into FindValueForKey template (between for-loop and return 0):
const Node *pValueMerge = FindValueForKey(std::string("<<"));
if(pValueMerge) {
return pValueMerge->FindValueForKey(key);
}
The problem (as I mentioned on the issue page) is that the spec allows
<<: [*dict1, *dict2]
to merge multiple dictionaries; but it appears you don't need that.
Ask 'yaml-cpp' to implement the feature.
Problem
Using YAML merge keys.
Solution
Other scripts, other parser, other way to parse or whatever is good if I can use merge feature.
The following YAML implementations support the desired feature as of this writing
Ruby 2.x
Python 2.x // 3.x