Call a function inside a hamlet file

103 Views Asked by At

I have writen a small language lookup with a function

getValue :: String -> String -> String
getValue lang key = ( 
    head $
    filter ((== key) . head) langData)
    !! getLangIndex lang

now i want to call this lookup function inside a hamlet file.

Is this possible and how do i have to change the function to make it callable?

2

There are 2 best solutions below

0
arrowd On

You can use any Haskell expression which is in scope using #{} interpolation. Just make sure you function produces something of ToHTML instance.

0
Janthelme On

Something like this should work:

myhamlet key lang = [hamlet|
    <h1> for key = #{key}, lang = #{lang}, value = #{getValue lang key}
 |]

... or in a .hamlet file :

    <h1> for key = #{key}, lang = #{lang}, value = #{getValue lang key}

(assuming that key and lang are in scope).