Private/Resolve-TemplateTokens.ps1
|
function Resolve-TemplateTokens { <# .SYNOPSIS Replace all {{TOKEN}} placeholders in a template string with resolved values. .PARAMETER Content The template content string containing {{TOKEN}} placeholders. .PARAMETER Tokens Hashtable of token name → value. Token names should NOT include the braces. .OUTPUTS [string] The content with all tokens resolved. Unresolved tokens are removed. #> [CmdletBinding()] [OutputType([string])] param( [Parameter(Mandatory)] [string]$Content, [Parameter(Mandatory)] [hashtable]$Tokens ) foreach ($key in $Tokens.Keys) { $Content = $Content -replace [regex]::Escape("{{$key}}"), $Tokens[$key] } # Remove any remaining unresolved tokens (clean output) $Content = $Content -replace '\{\{[A-Z_]+\}\}\n?', '' $Content } |