I'm using Handlebars.js to display an element depending on whether a string matches the current user's username.
I'm actually looping through a collection blogs
and this is where the attribute author
comes into play. Regardless, author.username
represents some username string and this is available to me. My problem is that if I change user.attributes.username
to some pre-defined string, i.e. "martin" then the condition checks out and it displays the element the way I want. But I also have an attribute user.attributes.username
and this renders just fine outside the #ifEquals
condition. I really want to compare author.username
with this attribute, and not some pre-defined string.
How can I compare two attributes, i.e. author.username
with user.attributes.username
instead of author.username
with "martin"
?
Both author.username
and user.attributes.username
have the same value. This doesn't work for me right now but is what I ultimately want:
<a href="#" onClick="return false;"><span class="delete-container" style="cursor: pointer" data-blog-id=""><span class="typcn typcn-arrow-sorted-down hvr-pulse-grow" style="color: gray; font-size: 30px;"></span></span></a>
This works but isn't sufficient for my purposes:
<a href="#" onClick="return false;"><span class="delete-container" style="cursor: pointer" data-blog-id=""><span class="typcn typcn-arrow-sorted-down hvr-pulse-grow" style="color: gray; font-size: 30px;"></span></span></a>
Handlebars.js Helper:
<script>
Handlebars.registerHelper('ifEquals', function(arg1, arg2, options) {
return (arg1 == arg2) ? options.fn(this) : options.inverse(this);
});
</script>
Aucun commentaire:
Enregistrer un commentaire