6

After some clarification I restate my question as follows.

In a jquery template I've got sth. messy like this to use a return value of a function

<p class="hidden">${$data.score = getScore(results)}</p>

{{tmpl(homeTeam, {score: score}) "#scoreTemplate"}}

Can this be simplified - like the following, which unfortunately doesn't do the trick?

{{tmpl(homeTeam, {score: getScore(results)}) "#scoreTemplate"}}

Many thanks,
Robson

SunnyRed
  • 3,214
  • 3
  • 32
  • 54
  • Sidenote: I do know, that it's generally a good idea to put as few logic inside your template as possible (e.g. see: http://stackoverflow.com/questions/3896730/whats-the-advantage-of-logic-less-template-such-as-mustache). Anyway, there might be circumstances where a solution to the problem above could be the right or at least the simplest call. Therefore any solution is still very appreciated. – SunnyRed Aug 09 '11 at 21:07

1 Answers1

1

Try something like this,

{{tmpl(
homeTeam, 
{
     teamRole: 'homeTeam', 
     score: d = getScoreByMatch($data, true)
}
) "#scoreTemplate"}}

OR

{{tmpl(
roadTeam, 
{
    teamRole: 'roadTeam', 
    score: d = ${getScoreByMatch($data, false)}
}
) "#scoreTemplate"}}

I have never worked with jquery templates. But this score: d = getScoreByMatch($data, true) syntax will work in javascript.

What i did is just introduced a variable to get the result from getScoreByMatch() method and then assigning that variable's value to the score property.

I am not sure about it will work or not, but just give a try and see.

  • Thanks for your reply Tamil. Unfortunately both suggestion don't do it. The first own throws an "missing } after property list" and the second an "invalid property id" error. I am afraid this is a jquery templating issue / question. Nevertheless: Any help is welcome. – SunnyRed Jun 28 '11 at 13:15