Skip to content

Instantly share code, notes, and snippets.

@ali-abrar
Created October 30, 2015 14:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ali-abrar/080f8696c446c477b007 to your computer and use it in GitHub Desktop.
Save ali-abrar/080f8696c446c477b007 to your computer and use it in GitHub Desktop.
Reflex.Dom and Bootstrap CSS
import Reflex.Dom
import Data.Monoid
main :: IO ()
main = mainWidgetWithHead headWidget bodyWidget
headWidget = do
elAttr "link" ("href" =: "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" <> "rel" =: "stylesheet" <> "type" =: "text/css") $ return ()
bodyWidget = do
divClass "container" $ divClass "jumbotron" $ do
el "h1" $ text "Hello, world!"
el "p" $ text "This was made with Reflex and Bootstrap. This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information."
el "p" $ elAttr "a" ("class" =: "btn btn-primary btn-lg" <> "href" =: "https://github.com/ryantrinkle/try-reflex" <> "role" =: "button") $ text "Learn more"
@katychuang
Copy link

How would you expand the headWidget function to attach multiple files? The resulting DOM should not have a nested structure so I tried the following, which did not work since it doesn't return the m() type.

h :: MonadWidget t m => m ()
h = do
  elAttr "script" ("src" =: "script.js")
  elAttr "link" ("href" =: "style.css")

@oliver-batchelor
Copy link

    h :: MonadWidget t m => m ()
    h = do
      elAttr "script" ("src" =: "script.js") $ return ()
      elAttr "link" ("href" =: "style.css") $ return ()

@lgastako
Copy link

You should also be able to do something like:

    h :: MonadWidget t m => m ()
    h = do
      elAttr "script" ("src" =: "script.js") blank
      elAttr "link" ("href" =: "style.css") blank
      return ()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment