html if语句添加td,在.html模板页面中使用if语句(在<span>标记中)

博客讨论了如何在HTML模板中插入条件语句,特别是使用C#填充动态内容。作者遇到了在HTML中使用if语句显示文本的问题,并尝试了使用 Razor 解析器来运行嵌入的代码,但未成功。寻求解决方案,建议使用能够处理嵌入代码的模板引擎。
摘要由CSDN通过智能技术生成

任何人都可以帮助我在.html页面中使用if statement。在.html模板页面中使用if语句(在标记中)

我有一个etemplate.html页面。在其标签里面,我有一些{values},我从后面的代码填充。这样的:在C#中

Hi {Name},

Thank you for your order. Your project ID is {ProjId}. Your order

description is {description}.

// for {summary} == "" the below code shows if(!=""){---...

//I have tried using tags but not working

if({summary}!=""){

Your project summary is {summary}.

}

我的填充方法是:

private string PopulateConfirmationEmailBody(string Name, string ProjId,

string description, string summary)

{

string body = string.Empty;

using (StreamReader reader = new

StreamReader(Server.MapPath("~/etemplate.html")))

{

body = reader.ReadToEnd();

}

body = body.Replace("{Name}", Name);

body = body.Replace("{ProjId}", ProjId);

body = body.Replace("{description}", description);

body = body.Replace("{summary}", summary);

return body;

}

任何帮助,将不胜感激。提前致谢..!!

2017-08-07

Preet

+0

选中此:https://forums.asp.net/t/1944993.aspx?How+to+use+if+else+condition+to+display+text+in+HTML+ –

+0

@Sujith感谢您建议,但正如我所提到的,我已经尝试使用,但不工作 –

+0

现在你实际上没有做任何事情来运行你的HTML代码。你需要通过像Razor这样的解析器运行它,它将运行嵌入式代码并输出纯html。 –

给下面代码增加分页功能,要求细致,逻辑清楚,<form action="./../selectNews" method="post"> <input type="text" name="key" id="key" placeholder="请输入标题"/> <input type="submit" value="查询"/> <a href="zhuce.jsp">发布新闻</a> <a href="../user01/index.jsp">返回主页</a> </form> <table> <thead> <tr> <th>新闻编号</th> <th>新闻标题</th> <%-- <th>新闻内容</th>--%> <th>新闻类别</th> <th>发布人</th> <th>发布时间</th> <th>状态</th> <th>是否头条</th> <th colspan="4" align="center">操作</th> </tr> </thead> <tbody> <c:forEach items="${newslist}" var="u"> <tr> <td>${u.nid}</td> <td>${u.title}</td> <%-- <td>${u.content}</td>--%> <td>${u.type}</td> <td>${u.userName}</td> <td>${u.pubTime}</td> <td> <c:choose> <c:when test="${u.state==0}"><span style="color: ghostwhite">未审核</span></c:when> <c:when test="${u.state==1}"><span style="color: green">审核通过</span></c:when> <c:otherwise><span style="color: red">未通过</span></c:otherwise> </c:choose> </td> <td> <c:choose> <c:when test="${u.top==0}">否</c:when> <c:otherwise>是</c:otherwise> </c:choose> </td> <c:choose> <c:when test="${user.rule==1}"> <td> <a href="../NewsDetailServlet?nid=${u.nid}&op=show">查看</a> </td> <td> <a href="../NewsDetailServlet?nid=${u.nid}&op=update">修改</a> </td> <td> <a href="NewsDelete.jsp?nid=${u.nid}&title=${u.title}&userName=${user.userName}">删除</a> </td> <td> <a href="Newsshenhe.jsp?nid=${u.nid}&title=${u.title}&userName=${user.userName}">审核</a> </td> </c:when> <c:when test="${user.rule==0 && user.uid==u.uid}"> <td><a href="../NewsDetailServlet?nid=${u.nid}&op=show">查看</a></td> <td><a href="../NewsDetailServlet?nid=${u.nid}&op=update">修改</a></td> <td><a href="NewsDelete.jsp?nid=${u.nid}&title=${u.title}&userName=${user.userName}">删除</a></td> </c:when> <c:otherwise> <td><a href="../NewsDetailServlet?nid=${u.nid}&op=show">查看</a></td> </c:otherwise> </c:choose> </tr> </c:forEach> </table>
06-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值