2014-11-07 2 views
0

Я создаю страницу часто задаваемых вопросов, и я хочу вернуть массив, содержащий вопросы и ответы, в помощник космонавтов.Как прекомпилировать html в качестве помощников Spacebars в Meteor?

faq.js

var faqContents = [ 
    { 
    number: "One", 
    question: "Who needs acupuncture?", 
    answer: "<p>If you are suffering from pain or have a health problem that has not responded satisfactorily to Western medicine, you may benefit tremendously from acupuncture and herbs. In many cases, acupuncture has been more effective than conventional Western treatments. <br/>Your most valuable asset is good health. Invest in it wisely. Consider acupuncture.</p>") 
    }, { 
    number: "Two", 
    question: "What can I expect if treated?", 
    answer: "<p>Many conditions may be alleviated very rapidly by acupuncture; however, some conditions which have risen over a course of years will only be relieved with slow, steady progress. As in any form of healing, the patient’s attitude, diet, determination, and lifestyle will affect the outcome of a course of treatment.</p><p>Although there are techniques in Traditional Oriental Medicine for healing most conditions, there are medical circumstances that can be dealt with more effectively by Western Medicine. In such cases, your acupuncturist will recommend that you contact a physician. As in the case in China, acupuncture should be seen as complementary with Western Medicine.</p>" 
    } 
]; 

Template.faq.helpers({ 
    faqContents: function(){ 
     return faqContents; 
    } 
}); 

Но следующий код предоставляет фактические HTML-теги в тексте в окне обозревателя.

{{#each faqContents}} 

<div class="panel panel-default"> 
    <div class="panel-heading"> 
    <h4 class="panel-title"> 
     <a data-toggle="collapse" data-parent="#accordion" href="#collapse{{number}}">{{question}}</a> 
    </h4> 
    </div> 
    <div id="collapse{{number}}" class="panel-collapse collapse"> 
    <div class="panel-body"> 
     {{answer}} 
    </div> 
    </div> 
</div> 

{{/each }} 

Не знаете, как действовать.

ответ

1

Вместо {{answer}}{{{ answer }}}. Это говорит, что Meteor не избегает HTML-тегов и просто выводит необработанный HTML-код. Проверьте документы пробела в Github Repo.

Однако не рекомендуется только из-за безопасности. Что мешает вам использовать его так:

<p>{{ answer }}</p> 
+0

Amazing. Спасибо. Причина, по которой я не могу сделать это, как вы упомянули, состоит в том, что «ответ» может содержать много тэгов 'p' в разных местах, теги' '', теги img' и т. Д. – fuzzybabybunny

+0

Хороший способ получить безопасность и разрешить некоторые форматирование - использовать уценку - просто добавьте пакет 'markdown' и используйте' {{#markdown}} 'помощник. – stubailo

Смежные вопросы