Your question is very similar to the Person example in the compiled splices tutorial. You need to create a parent splice which will perform the shared computation. Call it computeXY
. Your template would look like this:
<computeXY>
<p>The first value is <x/>.</p>
<p>The second value is <y/>.</p>
</computeXY>
The computeXY
splice would perform the computation and use the runChildrenWith pattern to make the results of that computation available to its children as <x/>
and <y/>
tags. However, the runChildrenWith pattern works a bit differently with compiled splices. Here's how it would be implemented using the new API functions that have been added since the tutorial was written:
import Blaze.ByteString.Builder.Char8 (fromText)
import Heist.Compiled
runtimeTupleComputation = return ("foo", "bar")
splices = [ ("x", fromText . fst)
, ("y", fromText . snd)
]
computeXYSplice = withPureSplices runChildren splices runtimeTupleComputation