如何解决灰烬中的命名方块
是否可以使用“命名块”?例如,
{{#namedBlock "reusableBlock"}}
{{!-- block with a lot of properties and stuff that will look ugly if you hardcode in multiple places --}}
{{/namedBlock}}
代码中的其他地方
{{#if someCondition}}
<div class="wrapper">
{{reusableBlock}}
</div>
{{else}}
{{reusableBlock}}
{{/if}}
解决方法
我认为您正在寻找组件。 Named blocks是另一回事。
通过在终端中输入ember g component my-component
在Ember CLI中创建组件。或在.hbs
文件夹中手动创建app/components
文件。然后添加一些代码。
{{! my-component.hbs }}
<div class="my-component">
{{! Your code goes here }}
</div>
然后在另一个模板中,调用该组件。
{{! about-page.hbs }}
<h1>This is the about page</h1>
<MyComponent />
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。