Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
If we’re really going for true code reuse here, we’re eventually going to run into name
conflicts. Let’s say that there are two helper libraries that both use the class name
“foo” to affect styling. We want to avoid such a possibility. Therefore, we have
the newIdent function. This function automatically
generates a word that is unique for this handler.
Example 5-2. Using newIdent
getRootR=defaultLayout$doheaderClass<-liftnewIdenttoWidget[hamlet|<h1.#{headerClass}>MyHeader|]toWidget[lucius|.#{headerClass}{color:green;}|]
You might be wondering: what does lift mean? A Widget
is a monad transformer, sitting on top of a Handler.
newIdent is a function of a Handler, so we need to “lift” the function from the Handler layer to the Widget
layer to use it. We can actually use this same approach to perform complex actions, like
database queries, from within a widget. We’ll cover that when we discuss Yesod’s
monads.