diff --git a/Data/Variant.hs b/Data/Variant.hs
--- a/Data/Variant.hs
+++ b/Data/Variant.hs
@@ -28,6 +28,7 @@
 import Data.Maybe
 import Safe
 import Text.Printf
+import Data.Monoid
 
 data Variant = Null
              | Integer Integer
@@ -59,6 +60,17 @@
         compare Null _ = LT
         compare _ Null = GT
         compare _ _ = EQ
+
+instance Monoid Variant
+    where
+        mempty = Null
+        mappend Null a = a
+        mappend a Null = a
+        mappend (List xs) (List ys) = List (xs ++ ys)
+        mappend (AList xs) (AList ys) = AList (xs ++ ys)
+        mappend (List xs) (AList ys) = List (xs ++ map snd ys)
+        mappend (AList xs) (List ys) = List (map snd xs ++ ys)
+        mappend a b = String (flatten a ++ flatten b)
 
 flatten :: Variant -> String
 flatten (String s) = s
diff --git a/Text/HPaco/AST/Expression.hs b/Text/HPaco/AST/Expression.hs
--- a/Text/HPaco/AST/Expression.hs
+++ b/Text/HPaco/AST/Expression.hs
@@ -9,6 +9,7 @@
                 | AListExpression [(Expression,Expression)]
                 | VariableReference String
                 | EscapeExpression EscapeMode Expression
+                | TernaryExpression Expression Expression Expression
                 | BinaryExpression BinaryOperator Expression Expression
                 | UnaryExpression UnaryOperator Expression
                 | FunctionCallExpression Expression [Expression]
@@ -39,5 +40,7 @@
                     | OpBooleanOr
                     | OpBooleanXor
                     | OpInList
+                    | OpConcat
+                    | OpCoalesce
                     | Flipped BinaryOperator
                     deriving (Show, Eq)
diff --git a/Text/HPaco/Readers/Capo/Statements.hs b/Text/HPaco/Readers/Capo/Statements.hs
--- a/Text/HPaco/Readers/Capo/Statements.hs
+++ b/Text/HPaco/Readers/Capo/Statements.hs
@@ -185,14 +185,6 @@
 
 block = StatementSequence <$> braced statements
 
-keyword :: String -> Parser ()
-keyword str = do
-    string str
-    assertEndOfWord
-
-assertEndOfWord :: Parser ()
-assertEndOfWord = notFollowedBy $ letter <|> digit <|> char '_'
-
 withSemicolon :: Parser a -> Parser a
 withSemicolon p = do
     v <- p 
diff --git a/Text/HPaco/Readers/Common.hs b/Text/HPaco/Readers/Common.hs
--- a/Text/HPaco/Readers/Common.hs
+++ b/Text/HPaco/Readers/Common.hs
@@ -11,8 +11,9 @@
     , identifier
     , path
     , anyQuotedString, singleQuotedString, doubleQuotedString
-    , assertStartOfInput
-    , assertStartOfLine
+    , assertStartOfInput, assertStartOfLine
+    , assertEndOfWord, assertEndOfOperator
+    , keyword, operatorKeyword
     )
 where
 
@@ -100,3 +101,20 @@
 
 path :: Parser s String
 path = many1 $ try $ noneOf " \t\r\n%()"
+
+keyword :: String -> Parser s ()
+keyword str = do
+    string str
+    assertEndOfWord
+
+assertEndOfWord :: Parser s ()
+assertEndOfWord = notFollowedBy $ letter <|> digit <|> char '_'
+
+operatorKeyword :: String -> Parser s ()
+operatorKeyword str = do
+    string str
+    assertEndOfOperator
+
+assertEndOfOperator :: Parser s ()
+assertEndOfOperator = notFollowedBy $ oneOf "!@#$%^&*_-+=;:,./?\\|<>~`"
+
diff --git a/Text/HPaco/Readers/Paco/Expressions.hs b/Text/HPaco/Readers/Paco/Expressions.hs
--- a/Text/HPaco/Readers/Paco/Expressions.hs
+++ b/Text/HPaco/Readers/Paco/Expressions.hs
@@ -7,8 +7,24 @@
 import Text.HPaco.Readers.Common
 import Text.HPaco.AST.Expression
 
-expression = booleanExpression
+expression = ternaryExpression
 
+ternaryExpression = do
+    ex1 <- booleanExpression
+    ss_
+    try (ternaryTail ex1) <|> return ex1
+    where
+        ternaryTail ex1 = do
+            operatorKeyword "?"
+            ss_
+            ex2 <- ternaryExpression
+            ss_
+            char ':'
+            ss_
+            ex3 <- ternaryExpression
+            ss_
+            return $ TernaryExpression ex1 ex2 ex3
+
 booleanExpression =
     binaryExpression
         [("&&", OpBooleanAnd),
@@ -36,12 +52,19 @@
 
 additiveExpression =
     binaryExpression
-        [("+", OpPlus), ("-", OpMinus)]
+        [("++", OpConcat),
+         ("+", OpPlus),
+         ("-", OpMinus)]
         multiplicativeExpression
 
 multiplicativeExpression =
     binaryExpression
         [("*", OpMul), ("/", OpDiv), ("%", OpMod)]
+        coalesceExpression
+
+coalesceExpression =
+    binaryExpression
+        [("??", OpCoalesce)]
         (try traditionalFunctionCallExpression <|> postfixExpression)
 
 binaryExpression :: [(String, BinaryOperator)] -> Parser s Expression -> Parser s Expression
@@ -119,6 +142,7 @@
                  <|> stringLiteral
                  <|> listExpression
                  <|> alistExpression
+                 <|> boolLiteral
                  <|> varRefExpr
                  <|> bracedExpression
 
@@ -190,6 +214,9 @@
 stringLiteral = do
     str <- anyQuotedString
     return . StringLiteral $ str
+
+boolLiteral :: Parser s Expression
+boolLiteral = try (keyword "true" >> return (BooleanLiteral True)) <|> try (keyword "false" >> return (BooleanLiteral False))
 
 varRefExpr :: Parser s Expression
 varRefExpr = do
diff --git a/Text/HPaco/Readers/Paco/Include.hs b/Text/HPaco/Readers/Paco/Include.hs
--- a/Text/HPaco/Readers/Paco/Include.hs
+++ b/Text/HPaco/Readers/Paco/Include.hs
@@ -25,6 +25,7 @@
     subAst <- liftIO $ reader fn src
     let stmt = astRootStatement subAst
     modifyState (\s -> s { psDeps = fn:psDeps s ++ astDeps subAst })
+    modifyState (\s -> s { psDefs = psDefs s ++ astDefs subAst })
     return $ maybe stmt (\(ident, expr) -> LetStatement ident expr stmt) innerContext
     where
 
diff --git a/Text/HPaco/Readers/Paco/Statements.hs b/Text/HPaco/Readers/Paco/Statements.hs
--- a/Text/HPaco/Readers/Paco/Statements.hs
+++ b/Text/HPaco/Readers/Paco/Statements.hs
@@ -5,6 +5,7 @@
 
 import Control.Monad
 import Control.Monad.IO.Class
+import Control.Applicative ((<$>))
 import System.IO.Strict
 import System.FilePath
 import System.IO (withFile, IOMode (ReadMode))
@@ -35,6 +36,7 @@
           <|> try forStatement
           <|> try defStatement
           <|> try callStatement
+          <|> try literalBlock
           <|> try commentStatement
           <|> try includeStatement
           <|> try interpolateStatement
@@ -54,6 +56,12 @@
         (try (discard commentStatement) <|> discard anyChar)
         (try $ string "--%}")
     return NullStatement
+
+literalBlock :: Parser Statement
+literalBlock =
+    simpleTag "literal" >>
+    PrintStatement . StringLiteral <$>
+        manyTill anyChar (try $ simpleTag "endliteral")
 
 includeStatement :: Parser Statement
 includeStatement = do
diff --git a/Text/HPaco/Writers/Javascript.hs b/Text/HPaco/Writers/Javascript.hs
--- a/Text/HPaco/Writers/Javascript.hs
+++ b/Text/HPaco/Writers/Javascript.hs
@@ -280,6 +280,15 @@
             writeExpression e
             write "))"
 
+        TernaryExpression cond trueBranch falseBranch -> do
+            write "(("
+            writeExpression cond
+            write ") ? ("
+            writeExpression trueBranch
+            write ") : ("
+            writeExpression falseBranch
+            write "))"
+
         BinaryExpression (Flipped op) left right ->
             writeExpression $ BinaryExpression op right left
 
@@ -303,6 +312,13 @@
             writeExpression right
             write ")"
 
+        BinaryExpression OpCoalesce left right -> do
+            write "((function(a,b){if (a) return a; if (typeof(a) == 'undefined' || typeof(a) == 'object') return b; return a;})("
+            writeExpression left
+            write ","
+            writeExpression right
+            write "))"
+
         BinaryExpression o left right -> do
             let opstr = case o of
                             OpPlus -> "+"
@@ -320,27 +336,35 @@
                             OpNotLess -> ">="
                             OpBooleanAnd -> "&&"
                             OpBooleanOr -> "||"
-            if o `elem` numericOps
-                then write "(Number("
-                else write "(("
-            writeExpression left
-            write ")"
+                            OpConcat -> "+"
+            write "("
+            wrappedArg o left
             write opstr
-            if o `elem` numericOps
-                then write "Number("
-                else write "("
-            writeExpression right
-            write "))"
-            where numericOps = [
-                     OpPlus,
-                     OpMinus,
-                     OpMul,
-                     OpDiv,
-                     OpMod,
-                     OpGreater,
-                     OpLess,
-                     OpNotGreater,
-                     OpNotLess ]
+            wrappedArg o right
+            write ")"
+            where
+                numericOps = [
+                    OpPlus,
+                    OpMinus,
+                    OpMul,
+                    OpDiv,
+                    OpMod,
+                    OpGreater,
+                    OpLess,
+                    OpNotGreater,
+                    OpNotLess ]
+                stringOps = [
+                    OpConcat ]
+                wrappedArg o i =
+                    let wrapWord =
+                            if o `elem` numericOps
+                                then "Number"
+                                else if o `elem` stringOps
+                                then "String"
+                                else ""
+                    in write wrapWord >> write "(" >> writeExpression i >> write ")"
+               
+
 
         UnaryExpression o e -> do
             let opstr = case o of
diff --git a/Text/HPaco/Writers/JsonLisp.hs b/Text/HPaco/Writers/JsonLisp.hs
--- a/Text/HPaco/Writers/JsonLisp.hs
+++ b/Text/HPaco/Writers/JsonLisp.hs
@@ -114,6 +114,7 @@
         EscapeExpression EscapeHTML x -> writeWithHead "html" [x]
         EscapeExpression EscapeURL x -> writeWithHead "urlencode" [x]
         FunctionCallExpression fn args -> writeWithHead "call" (fn:args)
+        TernaryExpression expr true false -> writeList [ write $ StringLiteral "if", write expr, write true, write false ]
         BinaryExpression (Flipped op) lhs rhs -> writeExpression $ BinaryExpression op rhs lhs
         BinaryExpression op lhs rhs ->
             let optk = (binaryOperatorToken op) in
@@ -144,6 +145,8 @@
             binaryOperatorToken OpBooleanOr = "or"
             binaryOperatorToken OpBooleanXor = "xor"
             binaryOperatorToken OpInList = "in"
+            binaryOperatorToken OpConcat = "join"
+            binaryOperatorToken OpCoalesce = "denil"
             unaryOperatorToken :: UnaryOperator -> String
             unaryOperatorToken OpNot = "not"
 
diff --git a/Text/HPaco/Writers/PHP.hs b/Text/HPaco/Writers/PHP.hs
--- a/Text/HPaco/Writers/PHP.hs
+++ b/Text/HPaco/Writers/PHP.hs
@@ -302,12 +302,21 @@
         CallStatement identifier -> do
             wrapMode <- woWrapMode `liftM` ask
             writeIndent
-            write "eval("
+            write "if (isset("
             when (wrapMode == WrapClass) $ write "self::"
             write "$_macro_"
             write identifier
-            write ");"
+            write ")) {"
             endl
+            withIndent $ do
+                writeIndent
+                write "eval("
+                when (wrapMode == WrapClass) $ write "self::"
+                write "$_macro_"
+                write identifier
+                write ");"
+                endl
+            writeLn "}"
         SourcePositionStatement fn ln -> do
             c <- asks woSourcePositionComments
             when c $ do
@@ -455,6 +464,15 @@
             writeExpression e
             write "))"
 
+        TernaryExpression cond trueBranch falseBranch -> do
+            write "(("
+            writeExpression cond
+            write ") ? ("
+            writeExpression trueBranch
+            write ") : ("
+            writeExpression falseBranch
+            write "))"
+
         BinaryExpression (Flipped op) left right ->
             writeExpression $ BinaryExpression op right left
 
@@ -468,6 +486,15 @@
             writeExpressionPair left right
             write ")"
 
+        BinaryExpression OpCoalesce left right -> do
+            write "(is_null("
+            writeExpression left
+            write ") ? ("
+            writeExpression right
+            write ") : ("
+            writeExpression left
+            write "))"
+
         BinaryExpression o left right -> do
             let opstr = case o of
                             OpPlus -> "+"
@@ -486,6 +513,7 @@
                             OpBooleanAnd -> "&&"
                             OpBooleanOr -> "||"
                             OpBooleanXor -> " xor "
+                            OpConcat -> "."
             withParens $ do
                 writeExpression left
                 write opstr
diff --git a/Text/HPaco/Writers/Run.hs b/Text/HPaco/Writers/Run.hs
--- a/Text/HPaco/Writers/Run.hs
+++ b/Text/HPaco/Writers/Run.hs
@@ -14,6 +14,7 @@
 import Data.Variant
 import qualified Data.Variant as V
 import Data.Maybe
+import Data.Monoid
 import qualified Data.List as List
 import qualified Data.List.Split as Split
 import Control.Monad.State
@@ -130,6 +131,13 @@
                 return . AList $ zip keys' values'
 runExpression (EscapeExpression EscapeHTML e) = (String . htmlEncode . flatten) `liftM` runExpression e
 runExpression (EscapeExpression EscapeURL e) = (String . urlEncode . flatten) `liftM` runExpression e
+runExpression (TernaryExpression cond left right) = do
+    condVal <- runExpression cond
+    let expr =
+            if toBool condVal
+                then left
+                else right
+    runExpression expr
 runExpression (BinaryExpression op left right) = do
     lhs <- runExpression left
     rhs <- runExpression right
@@ -175,9 +183,14 @@
     Bool $ toDouble l <= toDouble r
 applyBinaryOperation (Flipped op) = \l -> \r ->
     applyBinaryOperation op r l
+applyBinaryOperation OpCoalesce = \l -> \r ->
+    case l of
+        Null -> r
+        otherwise -> l
 
 applyBinaryOperation OpMember = flip V.lookup
 applyBinaryOperation OpInList = V.elem
+applyBinaryOperation OpConcat = mappend
 
 applyBinaryOperation OpBooleanAnd = \l -> \r ->
     Bool $ toBool l && toBool r
diff --git a/hpaco-lib.cabal b/hpaco-lib.cabal
--- a/hpaco-lib.cabal
+++ b/hpaco-lib.cabal
@@ -1,5 +1,5 @@
 name:                hpaco-lib
-version:             0.18.0.0
+version:             0.22.0.0
 synopsis:            Modular template compiler library
 description:         Template compiler library, compiles template code into
                      PHP or Javascript, or interprets it directly.
