https://github.com/agrafix/hsmarty
Haskell implementation of a subset of the PHP-Smarty template language
https://github.com/agrafix/hsmarty
Last synced: about 1 year ago
JSON representation
Haskell implementation of a subset of the PHP-Smarty template language
- Host: GitHub
- URL: https://github.com/agrafix/hsmarty
- Owner: agrafix
- License: other
- Created: 2013-09-04T20:16:33.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2022-07-31T19:40:51.000Z (almost 4 years ago)
- Last Synced: 2025-04-04T15:46:22.668Z (about 1 year ago)
- Language: Haskell
- Size: 59.6 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HSmarty
Haskell implementation of a subset of the [PHP-Smarty][1] template language.
## Usage
```haskell
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Text.HSmarty
import qualified Data.HashMap.Strict as HM
import qualified Data.Text as T
main :: IO ()
main =
renderTemplate "test.tpl" $
HM.fromList [ ( "title", mkParam ("SomeTitle" :: T.Text))
, ( "list", mkParam (["a", "b"] :: [T.Text]))
]
```
## Implemented features
* Basic template parsing (See [Basic Syntax][2])
* Smarty comments
* Basic expressions (eg. `$var`, `$var.mapItem`, `$var[3]`, `$var@property`, `3+4`, ..)
* Branching (eg. `{if ..}`, `{elseif ..}`, `{else}`, ..)
* Looping with properties (eg. `{foreach $el as $k=>$v}`, `{$v@last}`, `{foreachelse}`, `{/foreach}`)
* Including other templates (`{include file='other.tpl'}`)
* Defining functions (`{function name='foo'}...{/function}`)
* Calling functions (`{foo arg1="bar"}`)
* Assigning variables (`{$foo=1+2+3}`)
* Capturing output into variables (`{capture name='blabla'}{$some}{/capture}`)
### Non-Smarty features
* Explicit scoping blocks (`{scope}{$localFoo=123}{$localFoo}{/scope}{* $localFoo not available here! *}`)
## Contributing
All constributions adding features of the "original" PHP-Smarty V3 are welcome. For any other contributions please discuss in an issue first. Note that by sending a PR you agree that all your code can be released under the BSD3 license as part of this project or otherwise.
[1]: http://www.smarty.net/
[2]: http://www.smarty.net/docs/en/language.basic.syntax.tpl