Public Function Parser_IF()
Dim PreLB
PreLB = ""
Parser_IF2(PreLB)
End Function
' 判斷標籤
Public Function Parser_IF2(ByVal PreLB)
On Error Resume Next
Dim Matches, Match,TestIF,TestVal,TestTrue,TestFalse
Dim NewPreLB
Reg.Pattern = "{" & PreLB & "If:(.+?)}([\s\S]*?){" & PreLB & "End If}"
Set Matches = Reg.Execute(Content)
For Each Match In Matches
TestVal=Match.SubMatches(1)
If Instr(LCase(TestVal), "{" & PreLB & "else}")>0 Then
TestVal=Replace(TestVal, "{" & PreLB & "else}", "{" & PreLB & "else}",1,-1,1):TestTrue=Split(TestVal, "{" & PreLB & "else}")(0):TestFalse=Split(TestVal, "{" & PreLB & "else}")(1)
Else
TestTrue=TestVal:TestFalse=""
End If
Execute ("If " & replace(Match.SubMatches(0),"'","""") & " Then TestIf = True Else TestIf = False")
If TestIF Then Content = Replace(Content, Match.Value, TestTrue) Else Content = Replace(Content, Match.Value, TestFalse)
If Err Then Response.Write "<font color=red>" & Lang_Parser_IF_Error & "[" & Match.SubMatches(0) & "]" & Err.Description & "</font>": Err.Clear: Response.End
Next
NewPreLB = PreLB & "-"
If RegExists("{" & NewPreLB & "If:(.+?)}([\s\S]*?){ & NewPreLB & "End If}", Content) Then Call Parser_IF2(NewPreLB) ' 多次調用
End Function
前臺模板用法
{if: XXXX}
{-if: XXXX}
{-else}
.....
{-End if}
{else}
.....
{end if}
即在嵌套的IF語句前加“-”,同理兩級嵌套加兩個,以此類推,層次足夠用