View Full Version : XTemplate variables

24 Nov 2012, 7:57 AM
I am working with search results returned from an Endeca search engine. I created many xtemplates to handle the display for each record and one xtemplate that determines which subtemplate to apply. This is working fine, but I need to know how to store values that I will need further down in the template. A good example is "search terms" that I will need to use to highlight later in the process. I know I can create member functions to further process values, but when should I set the value?

terms: '',
setTerms: function(values) {
this.terms = values.terms;
getTerms: function() {
return this.terms;

1) Do I set via calls at the beginning of the template?

<tpl if="values.properties.terms">
[{ this.setTerms(values) }]

The problem I experienced with this is that the value was always one search behind. My second search would produce terms from my first search.

2) Do I set from within my controller prior to calling the template?


3) Do I just tack on to the data that I pass the template during apply? If so, when I am in the weeds of the search results "tpl for" loop, how do I get way back up to the terms value at the root in the JSON? I say there was a parent, but can I chain that all the way back up?

26 Nov 2012, 8:02 AM
It sounds like instead of working around the issues you are having you need to rethink how you are doing things.