您的位置:首页 > 其它

最小修改实现5UCMS IF语句的嵌套

2011-12-14 07:28 260 查看
将 inc\class_template.asp 458行的 Parser_IF 函数整体注释掉,改成下面两个函数

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语句前加“-”,同理两级嵌套加两个,以此类推,层次足够用
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: