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
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!".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With