@{val name = customer.firstName + customer.lastName}
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/KDZsvAes2skJ.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
@name
Generates compiler error: "not found: value name"... the name variable is scoped to that code block.
Doing:
@{val name = "brian"; name}
works but only for that code block and its not really a variable.
Doing:
@name = {brian}
@name
Works fine because its like a function...but what about numbers:
@i=5 @i
doesn't work
but for numbers Doing:
@i={5}
@i+1
Or some combination there of doesn't really work as it gives you an html block "5+1" rather than integer 6.
@inc(v:Int) = @{
v + 1
}
@{
var i = 0
inc(i)
}
@i
Gives a compile error for the last line: not found: value i.... because its local to the code block
Of course if you specify an optional parameter to the template with a default value (that no one else uses) you can use that as a local variable but seems wrong.--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/n58cr5XLmCUJ.
@defining(customer.firstName + customer.lastName) { fullname =>
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
>> @defining(customer.firstName + customer.lastName) { fullname =>
>> <p>Hi there @fullname !</p>
>> }
Is the correct way to do it.
--
Guillaume Bort
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/2cVpyGP2dXAJ.
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/dwb7blKESxcJ.
To post to this group, send email to play-framework@googlegroups.com.
To unsubscribe from this group, send email to play-framework+unsubscribe@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-framework@googlegroups.com.
To unsubscribe from this group, send email to play-framework+unsubscribe@googlegroups.com.
So, is there something non-functional about defining local vals inside a function?I'm currently prototyping the conversion of a rather large, high-traffic website from PHP/Zend to Play 2, and the lack of local vals is one of Play 2's most obvious shortcomings. The @defining syntax is a little verbose, in my opinion, especially for multiple vals. And I don't like having to introduce more levels of nesting.
As far as I can tell, there's no fundamental reason not to support a syntax like this:@(i: Int, j: Int)@val k = i + jI can insert the val definition in the generated scala and it compiles fine.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/NyvJMy_BGvwJ.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
@(vars:utils.VarMap)
@vars.put("newVar", "some value")
@vars.get("newVar")package utils;
import java.util.HashMap;import java.util.Map;
/** * A simple hack to use variables in scala templates. This is necessary because * the standard Map.put(K,V) returns V. */public class VarMap {
private Map<String, Object> vars = new HashMap<String, Object>();
public void put(String key, Object value) { vars.put(key, value); }
public Object get(String key) { return vars.get(key); }}
Are you guys doing the same or do you have better ways?
I also think the grammar of Scala/Play is so difficult to follow and ugly and very different from other languages.
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
try this in scala template
@import java.math.BigInteger; var i=1; var k=1
if you want string then
@import java.lang.String; val name="template"