Search code examples
haskellyesodtemplate-haskellhamlet

Missing imports from Hamlet libraries


This is the code snippet from O reilly - Yesod - Widgets,

getRootR = defaultLayout $ do
    setTitle "My Page Title"
    toWidget [lucius| h1 { color: green; } |]
    addScriptRemote "https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"
    toWidget [julius|
      $(function() {
        $("h1").click(function(){ alert("You clicked on the heading!"); });
      });
    |]
    toWidgetHead [hamlet| <meta name=keywords content="some sample keywords">|]
    toWidget [hamlet| <h1>Here's one way of including content |]
    [whamlet| <h2>Here's another |]
    toWidgetBody [julius| alert("This is included in the body itself"); |]

This code produces the error,

widget.hs:3:12: Not in scope: ‘defaultLayout’
widget.hs:4:3: Not in scope: ‘setTitle’
widget.hs:5:3: Not in scope: ‘toWidget’

What are the modules from Hamlet, i need to import to make this work? Does haskell has auto-completion feature, that will try to search and auto-import module names?


Solution

  • Import Yesod.Core and Yesod.Core.Widget, they will provide the appropriate functions.

    Also note that they have a online version of the book. And generally if you see import errors, do a search on Hoogle and in most of the cases you are likely to find a solution there.