Hi,
I’m running into a problem for which i haven’t found a solution yet. It may be simple.
In my template file, i am loading this collection which has been dynamically created. I’ll keep it down to a single object:
{"sites":
{
"creationDate": "2015.03.30",
"name": "My Site",
"description": "A beautiful thing"
}
}
From that collection, i’m creating links and creationDate for each item in my template. Like so:
<template name="sitesList">
<div id="sidebar">
<h4>Active Sites</h4>
<ul id="siteslist" class="list-unstyled">
{{#each sites}}
<li><a href="mySites/{{cleanedString name}}">{{name}}</a> | <span id="date">{{creationDate}}</span> <i class="fa fa-times delete"></i></li>
{{/each}}
</ul>
</div>
</template>
Notice that in the following line, i’m calling a template helper named cleanedString
that i use to strip white spaces and replace them with dashes, to lowercase the whole string and to sanitize the input:
<a href="mySites/{{cleanedString name}}">
Because i’m using the djedi:sanitize-html package, i need to run the sanitize function on the server. It is defined this way:
Template.sitesList.helpers({
'cleanedString': function(string) {
Meteor.call('sanitize', string, function(err, res) {
if (err) {
console.log(err);
} else {
console.log(res);
return res;
}
});
}
});
While on the server side, the sanitize
function is declared like so:
Meteor.methods({
sanitize: function(string) {
var saneString = sanitizeHtml(string);
// Replaces whitespace by dash, lowercase and return as string
var strippedStr = saneString.replace(/ /g,'-').toLowerCase();
console.log(strippedStr);
return strippedStr;
}
});
Now here is the problem. That line can’t seem to resolve to anything else than blankness:
<a href="mySites/{{cleanedString name}}">
But certainly, the variable name
containing the “My Site
” value from the collection is passed to the cleanedString
function. I know it because my console.log
calls both from the server AND from the client are sending back the right value: “my-site
”.
It seems like the problem is either with the evaluation of the template either with my code.
Anyone has any idea what did i do wrong?