[英]SWI-Prolog conditional inclusion in html//1
我有一些html段,这些段依赖于会话中设置的某些值,是否有可能以某种方式对包含的内容进行条件处理,这样我就不会最终复制大量的html代码? 或者,也许还有另一种方法不涉及html // 1?
foo -->
html([
div(p('I''m always displayed')),
{
http_session_data(Data),
% some other logic
},
div(p('I''m only displayed when there''s session data'))
)].
代码失败: ERROR: [Thread httpd@9999_3] Failed to translate to HTML: http_session_data(Data)
我通过将逻辑放在另一个DCG中并将其包含在html // 1中来弄清楚。
(
{
http_session_data(Data)
}
->
div(p('I''m only displayed when there''s session data'))
;
{true}
)
{true}
部分是为了摆脱控制台中的错误消息。
但是,此后我改变了主意,决定使用AngularJS来处理Html,因为Prolog对Html的支持对于复杂的DOM而言过于基础和痛苦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.