@@ -149,21 +149,21 @@ conditional = try $ do
149 string ")$"
149 string ")$"
150 -- if newline after the "if", then a newline after "endif" will be swallowed
150 -- if newline after the "if", then a newline after "endif" will be swallowed
151 multiline <- option False $ try $ skipEndline >> return True
151 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
159+ when multiline $ optional skipEndline
152 let conditionSatisfied = case lookup id' vars of
160 let conditionSatisfied = case lookup id' vars of
153 Nothing -> False
161 Nothing -> False
154 Just "" -> False
162 Just "" -> False
155 Just _ -> True
163 Just _ -> True
156− contents <- if conditionSatisfied
164+ return $ if conditionSatisfied
157− then liftM concat parseTemplate
165+ then ifContents
158− else do
166+ else elseContents
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
165− when multiline $ optional skipEndline
168for :: GenParser Char TemplateState String
168for :: GenParser Char TemplateState String
169for = try $ do
169for = try $ do