Skip to content

Instantly share code, notes, and snippets.

@Khady
Last active October 9, 2019 21:42
Show Gist options
  • Save Khady/fc87c1ec601e17e686e0864b7165c55a to your computer and use it in GitHub Desktop.
Save Khady/fc87c1ec601e17e686e0864b7165c55a to your computer and use it in GitHub Desktop.
tyxml jsx
open Tyxml;
module Custom = {
let createElement = (~children, ()) => {
Html.txt("ahrefs");
};
};
let template = (~name, ~validation_url) => {
<p>
"Hello "
{Html.txt(name)}
", please click on the "
<a href=validation_url> "link" </a>
" to verify your "
<Custom />
" account"
</p>;
};
open Tyxml
module Custom =
struct let createElement ~children () = Html.txt "ahrefs" end
let template ~name ~validation_url =
Html.p
(Html.Xml.W.cons (Html.Xml.W.return (Html.txt "Hello "))
(Html.Xml.W.cons (Html.Xml.W.return (Html.txt name))
(Html.Xml.W.cons
(Html.Xml.W.return (Html.txt ", please click on the "))
(Html.Xml.W.cons
(Html.Xml.W.return
(Html.a ~a:[Html.a_href validation_url]
(Html.Xml.W.cons (Html.Xml.W.return (Html.txt "link"))
(Html.Xml.W.nil ()))))
(Html.Xml.W.cons
(Html.Xml.W.return (Html.txt " to verify your "))
(Html.Xml.W.cons
(Html.Xml.W.return
((Custom.createElement ~children:[] ())[@JSX ]))
(Html.Xml.W.cons
(Html.Xml.W.return (Html.txt " account"))
(Html.Xml.W.nil ()))))))))
# Email_templates.Registration.template;;
- : name:string -> validation_url:string -> [> Html_types.p ] Tyxml_html.elt =
<fun>
# let print page = Format.asprintf "%a" (Tyxml.Html.pp_elt ()) page;;
val print : 'a Tyxml_html.elt -> string = <fun>
# let page = Email_templates.Registration.template ~name:"louis" ~validation_url:"https://ahrefs.com";;
val page : [> Html_types.p ] Tyxml_html.elt = <abstr>
# print page |> print_endline;;
<p>Hello louis, please click on the <a href="https://ahrefs.com">link</a> to verify your ahrefs account</p>
- : unit = ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment