FAQ Database Discussion Community


Is there a way to pass a Hamlet block as an argument to a function?

haskell,yesod,hamlet
Let's say that I have a generic content :: Widget -> Widget helper, which takes a Widget and wraps it in some HTML. Is is possible to call this function giving it the argument inline in the Hamlet file, similarly to what one would do in Ruby on Rails? For...

Send 301 redirect in Yesod

haskell,yesod
With this Yesod handler: myR :: Handler Html myR = redirect HomeR I can redirect using the 303/302 status code according to the documentation The documentation states that redirectWith shall be used for other status codes. What would be an example of using redirectWith with a 301 status code?...

Post and Get a variable using yesod server

haskell,yesod
var express = require('express') var app = express() var store = undefined app.post("/", function(req, res){ store = req.body }) app.get("/", function(req, res){ res.send(store) } app.listen(some_port_num) This is a simple nodejs/express server application which stores the http request body in a global variable and sends the same variable as responsse on...

Simplifying Persistent & Esqueleto code

haskell,yesod,persistent,esqueleto
I have a fairly simple query that does two outer joins. (A meal has many recipes which in turn have many foods). getMeals :: (MonadIO m) => Key DbUser -> SqlPersistT m [Meal] getMeals user = fmap deserializeDb $ E.select $ E.from $ \(m `E.InnerJoin` u `E.LeftOuterJoin` r `E.LeftOuterJoin` f)...

How can I store request-local information in Yesod middleware and retrieve it from a Handler?

yesod,middleware
Before any handler code is executed, I need to load some information about the user, which is determined by the request cookies, and then access that in all of my handler code. I've looked at the yesod-core codebase and found that I could override the yesodMiddleware function and provide a...

How can I query using persistent-mysql using withMySQLConn?

mysql,database,haskell,yesod,persistent
I'm using persistent-mysql and trying to find a way to execute a simple command from the SqlPersistM () monad. However I'm running into type errors. First there is withMySQLConn defaultConnectInfo, which has the following type (MonadLogger m, MonadBaseControl IO m, MonadIO m) => (Connection -> m a) -> m a...

how to break up the monolithic mkYesod block safely

haskell,module,hierarchy,yesod
This question is more to help my understanding of Yesod than anything else. Take the example at http://www.yesodweb.com/book/basics and in particular the code generated by the mkYesod TH function. The problem that I perceive is that this TH generates both the route data type (data Route HelloWorld = HomeR) and...

compile-time vs. run-time cost of Hamlet templates

haskell,yesod,hamlet
For the Hamlet template mechanism, I understand that the template is parsed at compile time, resulting in source code that contains calls to blaze-html combinators (and possibly other expressions because of interpolation). So the points (subtrees) where interpolation happens are known at compile-time. At run-time, we need to compute the...

SVG tags in hamlet shakespearean (yesod/haskell) templates?

haskell,yesod,hamlet
Is there a way to include tags in hamlet? If not, what are the workarounds/alternatives?

use runDB in a SubSite Yesod

haskell,persistence,yesod
i want create a post method in a SubSite to create a new entity, i have this AForm demoForm :: RenderMessage master FormMessage => Maybe Demo -> AForm (HandlerT master IO) Demo demoForm demo = Demo <$> areq textField (fieldSettingsLabel ("fieldone"::T.Text)) (demoFieldOne <$> demo) <*> areq intField (fieldSettingsLabel ("fieldone"::T.Text)) (demoFieldTwo...

Is there a Yesod alternative to the Rails' `link_to foo, bar, method: “delete”?

haskell,yesod
Is there a simple way to generate a link that uses a different method than GET in Yesod, such as in Ruby on Rails, where one can do link_to foo, bar, method: "post", which would submit the link via JavaScript? update: What Ruby on Rails does is that it generates...

What are hsfiles? Why use a “.hsfiles” extension instead of a regular “.hs”?

haskell,yesod
Reading Yesod's source code, I've encountered files with a ".hsfiles" extension. Example: mongo.hsfiles. What are them, why they were created and why use them?

In yesod (haskell), how do I load a plain html-formatted file (not a hamlet) as a widget?

haskell,yesod,shakespeare-text
How do I load a plain html-formatted file (not a hamlet-formatted file) as a widget? In other words I'm looking for the html equivalent of: toWidget $(whamletFile "test.hamlet") ...

Missing imports from Hamlet libraries

haskell,yesod,template-haskell,hamlet
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...

where does ^{pageBody pc} come from?

haskell,yesod
In default-layout-wrapper.hamlet file, there is ^{pageBody pc} which allows me to embed body content. I can find the pc part in Foundation.hs file. but where is pageBody constructed (in what file)? Same question for this variable #{pageTitle pc}.

Yesod Mform and hamlet

yesod,hamlet,yesod-forms
Hi I am new to yesod and following the documentation to make a form. In the documentation the form template was created in .hs file itself. But I have a separate hamlet where I want to customize. I want to access "fields" in my hamlet file. The expected type of...

Using JS-variable in Yesod handler's code

javascript,yesod,julius
I know that we can use Haskell data in the Julius-code, for example: $(function(){ $("section.#{sectionClass}").hide(); }); But how can I use JS-variable in the Haskell code? For example: ... in some .julius $(function set_global_variable( value ) { window.myGlobalValue = value; }); ... in some handler, pseudocode: getMyPageR :: Handler Html...

Composite Primary Key in Yesod

haskell,yesod,template-haskell
I am fairly new to Haskell and have been experimenting with yesod for about a week now. I have been trying to connect to an existing database that has a composite primary key in sqlite. I managed to get the code to work with Database.Persist.Sqlite as a standalone application. Here...

Couldn't match type Data.Enumerator.Internal.Iteratee with IO

haskell,yesod
import qualified Data.ByteString.Lazy as L import Data.Enumerator.List (consume) data App = App mkYesod "App" [parseRoutesNoCheck| /*Texts WikR GET --PathMultiPiece handler for all combinations / WikiR POST |] instance Yesod App getWikR :: [Text] -> Handler Text getWikR parts = return "" --defaultLayout [whamlet||] postWikiR = do bss <- lift consume...

Wildcard character asterisk in route path throws error

haskell,yesod
A simple yesod server code with a single handler for all GET requests i wrote as: {-# LANGUAGE TypeFamilies, QuasiQuotes, MultiParamTypeClasses, TemplateHaskell, OverloadedStrings #-} import Yesod data Links = Links mkYesod "Links" [parseRoutes| /* HomeR GET |] instance Yesod Links getHomeR = defaultLayout [whamlet|Go to page 1!|] main = warpDebug...

How can I run Yesod's DB actions in the REPL?

haskell,yesod,persistent
It is easy to run DB actions in the normal Handler workflow, since the runDB function can be used to transform the SqlPersistM actions into Handler ones. But there is no such way to convert SqlPersistM directly into IO using the default app settings. Looking at the Foundation.hs as its...

Yeson.json.object is applied to too many arguments

haskell,yesod,classy-prelude
import Yesod import Data.Text data App = App instance Yesod App mkYesod "App" [parseRoutes| / Home GET |] getHome :: String -> Handler Value getHome = object ["name" .= ("Adam"::Text)] main = warpDebug 2012 App throws error as, Couldn't match expected type ‘String -> Handler Value’ with actual type ‘Value’...

Which form to run?

haskell,yesod
I'm trying to build a page with multiple similar forms on one page. Each form is very simple, it provides an integer input and a submit button. Each form corresponds to a counter, and the counter is supposed to be increased when the form is submitted. incrementCounterForm :: Entity Counter...

Reading the run mode in Yesod

testing,yesod
How can I determine the run mode (Development, Testing, Staging, Production) in a Yesod application? I have a service that should return a value only in Development and Testing modes. The value is a secret token that will be sent as part of a validation for a newly registered user....

Yesod errors when compiling

haskell,yesod
For AForm I have got some compile errors: 1. For default Int value: data Person = Person { name :: Text , age :: Maybe Int } deriving Show formPerson :: AForm Handler Person formPerson = Person <$> areq textField "Person Name" Nothing <*> aopt intField "Person Age" (Just 25)...

A typeclass instance that needs configuration data. What are my options?

haskell,configuration,yesod,typeclass
Using yesod and persistent, I made what I think is a handy type to handle Markdown data: {-# LANGUAGE OverloadedStrings #-} module Utils.MarkdownText where import Prelude import Data.Text.Lazy import Data.Text as T import Database.Persist import Database.Persist.Sql import Text.Blaze import Text.Markdown newtype MarkdownText = MarkdownText { rawMarkdown :: T.Text } instance...

How can I embed both Text and Widget in another Widget in Yesod?

haskell,yesod,hamlet
Given a simple example like this glyphicon :: Text -> Widget glyphicon name = toWidget [hamlet|<span class="glyphicon glyphicon-#{name}">|] foo :: ToMarkup a => a -> Widget foo content = toWidget [hamlet|<div class="foo">#{content}</div>|] Is there a builtin mechanism in Yesod which would allow me to do both foo "some text" and...

How to specify type for class constrained value?

haskell,yesod,typeclass,persistent,monad-transformers
I'm trying to use a type signature on the result of the following persistent call. I can't figure out how to define the signature for something that's parameterized and class constrained such as the m inside of the transformer below: saveMyStuff :: MonadIO m => Int -> SqlPersistT m Stuff...

Where to store API keys and other 'secrets' in a yesod app

haskell,yesod,api-key
I'm trying out a yesod applications which I will eventually put up on github or similar. I will use oauth2 with google which means I have to provide an email and secret token. Which I obviously do not want up on github. What is a good place to store these...

Yesod CSS lucius

html,css,twitter-bootstrap,yesod
I have made a table in my hamlet file: <table> $forall ivlist <- y <tr> $forall iv <- ivlist <td>^{fvInput iv} and its respective css in lucius file: td { width:1em; height:1em; } The CSS was also generated as expected,but the output was different. When I change the height and...

In Yesod/Haskell, how do I use data from IO with the variable interpolation functionality?

haskell,io,monads,yesod
How do I take values from an IO monad and interpolate into a yesod widget? For example, I want to interpolate the contents of a file into hamlet: (readFile "test.txt") >>= \x -> toWidget $ [hamlet| <p> text: #{x} |] or equivalently: contents <- (readFile "test.txt") toWidget $ [hamlet| <h2>...

Error when starting Yesod app on openshift - command line args?

openshift,yesod
I am getting the following error when (re)starting my Yesod app on openshift: server: InvalidYaml (Just (YamlException "Yaml file not found: xxx.xxx.xxx.xxx")) Where xxx.xxx.xxx.xxx is an IP address. I did find a link to a Heroku+Yesod issue saying something about "removing an argument" but it didn't say from where, and...

Haskell Yesod: How to read text from file and apply variable interpolation to its content?

haskell,markdown,interpolation,yesod
I have quite big markdown text hardcoded inside my handler function currently. To render it I use whamlet quasiquoter and Text.Markdown.markdown from markdown package: let md :: L.Text md = "#Some markdown stuff" authLayout $ [whamlet| <div .StaticContent> #{markdown def md} |] There are some hardcoded links in the text...

why is the cabal sandbox inited after installing yesod-bin?

cabal,yesod
On the Yesod homepage (http://www.yesodweb.com/page/quickstart) the following installation sequence is suggested: wget http://www.stackage.org/lts/cabal.config cabal update # download package list cabal install alex happy yesod-bin # install build tools yesod init --bare # answer questions as prompted cabal sandbox init # set up a sandbox cabal install --run-tests # install libraries...

Yesod: Stuck in book “Seven Web frameworks in seven weeks”

haskell,yesod
I installed Yesod according to the quick start guide. I bought the book "Seven Web frameworks in seven weeks" and I'm trying to follow along. I'm on page 204 (Day 1: Working with models). When I enter ghci Model.hs in order to enter some data into the database, as the...

Yesod - how to make addScriptRemote add the script in the head section?

haskell,yesod,script-tag,yesod-forms
In Yesod/Haskell, I'd like to call addScriptRemote and have it add the <script> tag in the head section. As is, it seems to add the script only to the body section.

Cabal build failure on ReadArgs when deploying to OpenShift

haskell,openshift,cabal,yesod
I am trying to deploy a web application to OpenShift. My app is written with Yesod web framework. I would like to use the Yesod cartridge from Haskell wiki. I can create the application and deploy the example supplied with the cartridge. However, when I add more dependencies to the...

Yesod and dynamic Bootstrap/jQuery form

jquery,forms,yesod
I work with an existing form built with Bootstrap. But this form contains <input>s dynamically added with jQuery. So user can add any number of inputs before submitting the form. I know that the names of these inputs forms like attr1, attr2, attr3 and so on. But I cannot run...