Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a function from an .ERL to .YAWS file

Tags:

erlang

yaws

I am very new to YAWS and ERLANG and would like to call a function from a different .erl file to the YAWS page.

i.e. I have a page called webpage.yaws and have another file called utilities.erl and would like to call a function from utilities.erl in webpage.yaws

Any ideas?

Thanks

like image 439
cgval Avatar asked Oct 17 '12 07:10

cgval


1 Answers

It's very simple, just call the function like you would normally do in Erlang programs, i.e. Module:func_name(arguments) the only thing you need to do is make sure Yaws knows where to find the compiled BEAM file. In the Yaws configuration file add:

ebin_dir = /tmp/ebin

Compile your utilities.erl, put the BEAM file in /tmp/ebin and you can call your utility functions from the webpage.yaws file.

Full example:

website.yaws:

 <html>
  <erl>
    out(Arg) ->
       D=utilities:get_some_strings(),
       {html, ["Retrieved from utilities: ", D]}.
  </erl>    
 </html>

utilities.erl:

-module(utilities).

-export([get_some_strings/0]).

get_some_strings() ->
    "hello world!".
like image 138
johlo Avatar answered Nov 15 '22 08:11

johlo