【问题标题】:erlang n2o render get &lt;span id=&quoterlang n2o 渲染获取 <span id=&quot
【发布时间】:2016-08-02 17:02:26
【问题描述】:

我想用 n2o 和 rebar3 写网页。 但是我的页面有问题,代码在这里。

index.erl

-module(index).
  -compile(export_all).
  -include_lib("n2o/include/wf.hrl").
  -include_lib("nitro/include/nitro.hrl").




  main() -> #dtl{file="prod",app=web, ext="dtl", bindings=[{body,body()} ]}.

  body() ->
      [ #span   { id=display },                #br{},
        #span   { body="Login: " },            #textbox{id=user,autofocus=true}, #br{},
        #span   { body="Join/Create Feed: " }, #textbox{id=pass},
        #button { id=loginButton, body="Login",postback=login,source=[user,pass]} ].

prod.dtl

<html >
<head>
  <title>{{title}}</title>
</head>
<body>
            {{body}}
</body>
</html>

我得到了结果:

<html >
<head>
  <title></title>
</head>
<body>
            &lt;span id=&quot;display&quot;&gt;&lt;/span&gt;&lt;br/&gt;&lt;span&gt;Login: &lt;/span&gt;&lt;input id=&quot;user&quot; type=&quot;text&quot; autofocus=&quot;true&quot;/&gt;&lt;br/&gt;&lt;span&gt;Join/Create Feed: &lt;/span&gt;&lt;input id=&quot;pass&quot; type=&quot;text&quot;/&gt;&lt;button id=&quot;loginButton&quot; type=&quot;button&quot;&gt;Login&lt;/button&gt;
</body>
</html>

我怎样才能得到'

【问题讨论】:

  • prod.etl 中将{{body}} 更改为{{body | safe}} 是否有效?
  • 您使用的是哪个版本的 DTL? N2O 最高支持 0.8。更新版本由您决定。
  • @Dogbert 它的工作....谢谢
  • @Dogbert 谢谢,这对我来说是新的 :-)
  • @5HT 我使用 rebar3_erlydtl_plugin 。它使用最新版本的 erlydtl .so...

标签: web erlang n2o


【解决方案1】:

erlydtl 启用了 this commit{{}} 内的值的自动转义(另请参阅 #80#120)。如果您使用包含此提交的版本(从页面上看,它看起来像 0.9.0 或更高版本),您必须手动将该值标记为安全。

代替:

{{ body }}

做:

{{ body | safe }}

注意:您应该注意将不受信任的字符串标记为安全的风险:https://en.wikipedia.org/wiki/Cross-site_scripting

【讨论】:

    猜你喜欢
    • 2020-11-21
    • 2019-06-21
    • 2017-10-14
    • 2022-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-13
    相关资源
    最近更新 更多