简体   繁体   中英

Specify template to be display in a 'render'

Im trying to use,the 'render' in ember.js, what I want to do is specify which template content will be render:

<div>
{{render "content"}}
</div>

<script type="text/x-handlebars" data-template-name="template1"> 
 content 1
<script>

<script type="text/x-handlebars" data-template-name="template2"> 
 content 2
<script>


App.ContentView = Ember.View.extend({
  templateName: validateSomething() ? 'template1' : 'template2',
});

That's what I have but is not working, is it possible make what I'm trying? Some other ideas??

Thanks!

I don't think templateName: validateSomething() ? 'template1' : 'template2' templateName: validateSomething() ? 'template1' : 'template2' will work. Why not use the Handlebars {{#if}}{{/if}} helper to determine what to render (within your content template)?

Update: This could be more what you are after:

<div>
{{render "content"}}
</div>

<script type="text/x-handlebars" data-template-name="content"> 
  {{#if condition}}
     {{view App.Template1View thisBinding="this"}}
  {{else}}
     {{view App.Template1View thisBinding="this"}}
  {{/if}}
<script>

<script type="text/x-handlebars" data-template-name="template1"> 
 content 1
<script>

<script type="text/x-handlebars" data-template-name="template2"> 
 content 2
<script>

I haven't been able to test this yet, but it should be enough to demonstrate the idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM