基于localStorage的Meteor激活模板
Meteor activating template based on localStorage
我的Meteor模板是这样排列的:
<template name="main">
{{#if youwashere}}
{{> content}}
{{#else}}
{{> introduction}}
{{/else}}
{{/if}}
</template>
为了确定用户以前是否访问过我的网站,我设置了一个本地存储,这很有效。然后我尝试这样称呼它:
Template.main.helpers({
youwashere(){ return localStorage.getItem('herebefore'); }
});
应该发生的事情是这样的:如果有本地存储项目 ('herebefore')
,那么它会显示名为 content
的模板。但如果您的计算机上没有该项目,它会向您显示模板 introduction
。帮助程序代码最终都没有显示,所以我想知道我做错了什么。
编辑:要存储在本地存储中,我使用以下内容:
Template.introduction.events({
'click #button':function(){
localStorage.setItem('herebefore', true);}
});
我是这样解决的。无论出于何种原因,else 语法都没有按照我希望的方式工作。
<template name="main">
{{#if beenhere}}
{{> currentevents}}
{{/if}}
{{#unless beenhere}}
{{> introduction}}
{{/unless}}
</template>
您 else
的语法有点不对:
<template name="main">
{{#if youwashere}}
{{> content}}
{{else}}
{{> introduction}}
{{/if}}
</template>
我的Meteor模板是这样排列的:
<template name="main">
{{#if youwashere}}
{{> content}}
{{#else}}
{{> introduction}}
{{/else}}
{{/if}}
</template>
为了确定用户以前是否访问过我的网站,我设置了一个本地存储,这很有效。然后我尝试这样称呼它:
Template.main.helpers({
youwashere(){ return localStorage.getItem('herebefore'); }
});
应该发生的事情是这样的:如果有本地存储项目 ('herebefore')
,那么它会显示名为 content
的模板。但如果您的计算机上没有该项目,它会向您显示模板 introduction
。帮助程序代码最终都没有显示,所以我想知道我做错了什么。
编辑:要存储在本地存储中,我使用以下内容:
Template.introduction.events({
'click #button':function(){
localStorage.setItem('herebefore', true);}
});
我是这样解决的。无论出于何种原因,else 语法都没有按照我希望的方式工作。
<template name="main">
{{#if beenhere}}
{{> currentevents}}
{{/if}}
{{#unless beenhere}}
{{> introduction}}
{{/unless}}
</template>
您 else
的语法有点不对:
<template name="main">
{{#if youwashere}}
{{> content}}
{{else}}
{{> introduction}}
{{/if}}
</template>