我有一个模板如下:
<div class= "comment-form m-2">
{% include "includes/comment_reply_form.html" %}</div>如果用户已通过身份验证,则html将显示表单。但是,如果用户没有登录,我想显示一个登录按钮。我正在用下面的javascript处理同样的事情。
$(".comment-reply-btn").click(function(event){
event.preventDefault();
if (user_is_authenticated === false) {
$(".comment-form").html('{% include "includes/reply.html" %}');
$(this).parent().next(".comment-reply").fadeToggle();
}
else {
$(this).parent().next(".comment-reply").fadeToggle();
}
});但是,它没有包含来自reply.html的html,而是在网页中显示{% include "includes/reply.html“%}。javascript没有问题,如果我添加
<p> You need to Login </p>在下面这行中。它运行良好:-
$(".comment-form").html('{% include "includes/reply.html" %}');但由于我的reply.html中需要更多选项,所以我想将其添加为includes。我尝试在{前面使用转义字符"/“,但没有帮助。
发布于 2018-08-20 03:47:46
不熟悉,但请尝试
<div class= "comment-form m-2">
<script>
document.write('{% include "includes/comment_reply_form.html" %}')
</script>
</div>https://stackoverflow.com/questions/51921252
复制相似问题