Skip to content

v1.3 - Lambda Support

Compare
Choose a tag to compare
@splumhoff splumhoff released this 11 May 15:02
· 4 commits to main since this release

This release adds "Lambda-Support" to PSMustache along with a few minor performance improvements.
You can simply pass a ScriptBlock as Member of a Hashtable to get the code executed.

The Lambda-Functions can be used in Interpolation-Tags {{MyFunction}} as well as in Sections.

When used in Interpolation Tags, the ScriptBlock is called without any parameters.

PS> ConvertFrom-MustacheTemplate -Template 'Current Time: {{Time}}' -Values @{'time' = { Get-Date }}

Current Time: 05/11/2021 17:00:00

In Sections-Tags the content of the section is passed to the ScriptBlock:

PS> ConvertFrom-MustacheTemplate -Template 'Current Date: {{#Time}}yyyy-MM-dd{{/Time}}' -Values @{'time' = {Get-Date -Format $args[0]}}

Current Date: 2021-05-11

You can grab the content of the section tags via $args[0] (as in the above example) or via params, when defined in the ScriptBlock:

ConvertFrom-MustacheTemplate -Template 'Current Time: {{#Time}}yyyy-MM-dd{{/Time}}' -Values @{'time' = {param($format) Get-Date -Format $format}}

Current Date: 2021-05-11

Hope you enjoy the new feature and find it useful. :-)