Comments (5)
Hi there,
It would be really hard to parse such conditions, but you can just create your custom helper, like i did for myself with if
Template7.registerHelper('if_compare', function (a, operator, b, options) {
var match = false;
if (
(operator === '==' && a == b) ||
(operator === '===' && a === b) ||
(operator === '!=' && a != b) ||
(operator === '>' && a > b) ||
(operator === '<' && a < b) ||
(operator === '>=' && a >= b) ||
(operator === '<=' && a <= b)
) {
match = true;
}
if (match) return options.fn(this);
else return options.inverse(this);
});
And then use it like:
{{#if_compare a ">" b}} ... {{/if_compare}}
{{#if_compare a "===" b}} ... {{else}} ... {{/if_compare}}
So you can do the same for unless
helper
from template7.
OK thanks vladimir, I will do it
from template7.
Hello again,
Sorry but It won't work :
T7.registerHelper('unmatch', function (a, b, options) {
if (a !== b) {
return options.fn(this, options.data);
} else {
return options.inverse(this, options.data);
}
});
test is ok but nothing is hide by Template7
from template7.
Ok my bad, I wasn't closing correctly my helper in template page
from template7.
Hello Framework team,
I want to pass a json object (or json string) from page to page from inside a template
I tried the following but do not succeed:
Below we call the template and present the json object.
We also tried to stringify the json but also with no result.
Can you advise please?
}).then(function(result){
console.log(JSON.stringify(result[0]));
Template7.registerHelper('stringify', function (context){ return JSON.stringify(context[0]); });
var foodsearchHTML = $('script#foodsearchresultTemplate').html();
var compiledFoodSearchTemplate = Template7.compile(foodsearchHTML);
foodHTML3 = compiledFoodSearchTemplate(result);
document.getElementById('content-wrap-foodsearch').innerHTML = foodHTML3;
});
The template is as follows:
<script id="foodsearchresultTemplate" type="text/template7">
<div class="list-block media-list">
<ul>
{{#each this}}
<li>
<a onclick="open7consumptionNew('{{#stringify this}}');" data-context-name="object.{{this}}" class="item-content item-link">
<!--<div class="item-media"><i class="icon icon-f7"></i></div>-->
<div class="item-inner">
<div class="row">
<div class="item-title col-70" style="padding-left:10px">{{this.title}}</div>
<div class="item-after col-30">{{this.unitNameFriendly}}</div>
</div>
</div>
</a>
</li>
{{/each}}
</ul>
</div>
</script>
from template7.
Related Issues (20)
- For loop expression HOT 1
- How to Assign The Select Element Value In a Loop HOT 2
- Предложение: реализовать возможность в js_if подниматься на уровень "вверх", как в обычном if
- Thier is a way to create global nav or footer?
- escaping undefined and null
- Несколько предложений по расширению шаблонов
- Going back to "each"-context , after accessing parrent variable.
- How convert float (number) to string?
- variable helper HOT 1
- each use hasOwnProperty the inherited properties are not displayed.
- Parameterized partials
- how to use in expressjs?
- Can not compile
- js_if: проверка на свойства объекта, которое null
- QUESTION: Precompile templates HOT 1
- js not working in IOS? HOT 1
- #js_if: Cannot read property 'constructor' of undefined
- Feature {{@index + 1}} HOT 1
- issue in html attribute when value has spaces HOT 1
- Documentation website is down! HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from template7.