Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using elm for front end development + serving dynamic elm pages though haskell

Tags:

elm

I started with elm yesterday and I really enjoy using it. Without any experience in front end development I could build a nice looking webpage in only 30 lines of code, which is amazing.

Now I really want to use it in a real life example, I want to build a small blog. But I need a way to communicate with elm. For example I need to query my database and I get a list of blog entries [Blog] and now I need to pass them to elm.

I am not sure how I would do it. I was looking though the popular haskell frameworks like yesod snap and happstack and the first thing that I found was http://hackage.haskell.org/package/snap-elm-0.1.1.2/docs/Snap-Elm.html

But it seems it is intended for serving static elm files, but I need to pass arguments to it.

Any framework that you would recommend me that already has elm support for serving dynamic elm pages?

And if not, how would you do it?

My idea was just to use elm as a skeleton and then I generate a normal html file with yesod snap or happstack and integrate this file into elm. Would this be possible?

Something that would look like this

container 1000 1000 middle <| displayHtml "/pages/my_generated_html_page.html"

Edit:

My first hacky solution was this

tPage = plainText "<script src=\"http://code.jquery.com/jquery-1.10.1.min.js\"></script>\n
<script> \n
$(function(){\n
$(\"#includedContent\).load(\"/home/maik/b.html\"); \n
});\n
</script> \n
<div id=\"includedContent\"></div>\n"

Unfortunately I am not allowed to use script tags in elm.

like image 631
Maik Klein Avatar asked Nov 11 '22 17:11

Maik Klein


1 Answers

I recommend studying elm-lang.org's source code. The majority of it is pure Elm but there are pages that are generated on the server side with Haskell.

like image 179
thSoft Avatar answered Dec 18 '22 13:12

thSoft