@@ -149,21 +149,21 @@ conditional = try $ do
149149 string ")$"
150150 -- if newline after the "if", then a newline after "endif" will be swallowed
151151 multiline <- option False $ try $ skipEndline >> return True
152+ ifContents <- liftM concat parseTemplate
153+ -- reset state for else block
154+ setState $ TemplateState pos vars
155+ elseContents <- option "" $ do try (string "$else$")
156+ when multiline $ optional skipEndline
157+ liftM concat parseTemplate
158+ string "$endif$"
159+ when multiline $ optional skipEndline
152160 let conditionSatisfied = case lookup id' vars of
153161 Nothing -> False
154162 Just "" -> False
155163 Just _ -> True
156− contents <- if conditionSatisfied
157− then liftM concat parseTemplate
158− else do
159− parseTemplate -- skip if part, then reset position
160− setState $ TemplateState pos vars
161− option "" $ do try (string "$else$")
162− when multiline $ optional skipEndline
163− liftM concat parseTemplate
164− string "$endif$"
165− when multiline $ optional skipEndline
166− return contents
164+ return $ if conditionSatisfied
165+ then ifContents
166+ else elseContents
167167
168168for :: GenParser Char TemplateState String
169169for = try $ do