Since Hamlet allows to apply functions within an interpolation, you can simply use the function. Sample demo:
{-# LANGUAGE QuasiQuotes #-}
import Text.Hamlet (shamlet)
import Text.Blaze.Html.Renderer.String (renderHtml)
myClass :: Bool -> String
myClass _ = "dummyClass"
main :: IO ()
main = putStrLn $ renderHtml [shamlet|
<tr .#{myClass True}>
<td> dummy text |]
In ghci:
λ> main
<tr class="dummyClass"><td> dummy text </td>
</tr>