Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does one get strings (not string literals) into blazehtml attributes/element contents?

Tags:

types

haskell

The blazehtml tutorial and other blog posts make it very clear how to get string literals to work. I've got that. But how do I get strings (bytestrings, Data.Text, etc. would work too.) in general into the attributes/content of elements. Blazehtml looks great, but it seems pretty useless without that. =P

here's sample output and code to show the exact problem:


{-# LANGUAGE OverloadedStrings #-}

import Prelude
import qualified Prelude as P
import Text.Blaze.Html5
import Text.Blaze.Html5.Attributes
import qualified Text.Blaze.Html5 as H
import qualified Text.Blaze.Html5.Attributes as A

makeLink dest cont = renderHtml $ a ! src dest $ cont
*Main> let foo = "foo"
*Main> let bar = "bar"
*Main> makeLink foo bar

:1:9:
    Couldn't match expected type `AttributeValue'
           against inferred type `[Char]'
    In the first argument of `makeLink', namely `foo'
    In the expression: makeLink foo bar
    In the definition of `it': it = makeLink foo bar
like image 838
heartpunk Avatar asked Jul 22 '10 20:07

heartpunk


1 Answers

In this page of the documentation one finds the necessary functions: http://hackage.haskell.org/packages/archive/blaze-html/0.1.2/doc/html/Text-Blaze.html.

They are stringValue:: String -> AttributeValue and string:: String -> Html a. Problem Solved!

like image 157
heartpunk Avatar answered Oct 31 '22 19:10

heartpunk