How to compare two strings in template of Meteor Blaze
Posted By : Parveen Kumar Yadav | 27-Dec-2016
Some time we need to compare equality of two string value for hiding and showing some attribute or doing any conditionally work like if statement.So normally you check that value very easily in angular.js and other front-end technologies. But in blaze you can't simply compare two string by only equals operator . You need to create a helper by the help of that helper you can achieve comparison on two string in template html.
For example we have a template i.e test.html on which we want to show the button if the value of our session is equals to string i.e 'PACKED'.
Here you can use something like this:-
{{#if data == 'PACKED'}}But this is not going to work because blaze template work only on Boolean true false we can't compare directly two string. So we need to do something like this:-{{#if equals data 'PACKED'}}In the helper section you need to create a helper i.e:-You need to create a helper that is equals which take two argument and check equality if both are equal than it will return true. And in our template gets value of true and false accordingly and our if condition running perfectly. Hope it will help Thanks!Template.test.helpers({ equals: function(a, b) { return a == b; }, data: function() { var paramsStatus = Router.current().params._status; return paramsStatus; } })More From Oodles
Ready to innovate? Let's get in touch
Request for Proposal
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Parveen Kumar Yadav
Parveen is an experienced Java Developer working on Java, J2EE, Spring, Hibernate, Grails ,Node.js,Meteor,Blaze, Neo4j, MongoDB, Wowza Streaming Server,FFMPEG,Video transcoding,Amazon web services, AngularJs, javascript. He likes to learn new technologies