逃避Elixir eex模板

时间:2015-12-25 11:51:25

标签: templates elixir

我有两个文件包含:

def do_query_sys_status do
    f = EEx.eval_file("templates/do_query_sys_status.eex", 
            [assigns: [data: %{sysvar: 3, coutry_id: 1, webapi_key: "abc123456" }]])
    IO.puts f
end

和模板文件:

<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ser="https://webapi.allegro.pl/service.php">
    <x:Header/>
    <x:Body>
        <ser:DoQuerySysStatusRequest>
            <ser:sysvar><%= @data.sysvar =></ser:sysvar>
            <ser:countryId><%= @data.country_id %></ser:countryId>
            <ser:webapiKey><%= @data.webapi_key %></ser:webapiKey>
        </ser:DoQuerySysStatusRequest>
    </x:Body>
</x:Envelope>

运行后我收到错误:

** (SyntaxError) templates/do_query_sys_status.eex:7: keyword argument must be followed by space after: ser:
                   lib/eex/compiler.ex:34: EEx.Compiler.generate_buffer/4
                   lib/eex.ex:209: EEx.eval_file/3
    (bankinfo_api) lib/bankinfo_api.ex:25: BankinfoApi.do_query_sys_status/0
          (stdlib) erl_eval.erl:669: :erl_eval.do_apply/6
             (iex) lib/iex/evaluator.ex:117: IEx.Evaluator.handle_eval/5

是否有必要以某种方式逃避模板?我还没有找到任何方法。

1 个答案:

答案 0 :(得分:1)

您的代码中存在拼写错误

coutry_id

应该是

country_id

templates/do_query_sys_status.eex的第6行 应该是

<ser:sysvar><%= @data.sysvar %></ser:sysvar>