Skip to content

Instantly share code, notes, and snippets.

@tonyx

tonyx/example.fs Secret

Last active Mar 25, 2019
Embed
What would you like to do?
fsharp liquid example
// @leoningelse_gitlab ok, this is an exampla that can be easily
// changed in a way to avoid hidden fields, and html coding
// in App.fs file, before start the wweb server, you set the
// dotLiquid template dir
let cfg =
{ defaultConfig with
bindings = [ HttpBinding.createSimple HTTP "0.0.0.0" 8083 ] }
DotLiquid.setTemplatesDir ("liquidtemplates")
startWebServer cfg webPart
// in App.fs file, define the model containing paramater to be
// passed to templates
type MyModl = {HtmlParameter: string}
// in App.fs, handle a request containi the parameter
let formWithHiddenFields parameter =
let o = {HtmlParameter = parameter}
DotLiquid.page("myFile.html") o
// in liquidtemplates dir you have a myFile.html with
// a form like this:
<input type="hidden" id="custId" name="custId" value="{{model.html_parameter}}">
// you need to copy in your build directory the template, so if you use msbuild
// and a .fsproj file, you need the following lines:
<Content Include="liquidtemplates\myFile.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
// if you use some Ide like Ride, Xamarin, Visual Studio, I think it will add those lines
// for you when you add the html to the project. Alternatively you will do it
// by editing the .fsproj file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment