Reputation: 829
I'm trying to clean up some old code. How can I make this code more concise? Or is there a better way of doing this. It's an old classic .asp site with 2 domains being called from the files.
<% If (GetDomainType() = "CTH") Then %>
<meta HTTP-EQUIV="REFRESH" content="7; url=http://www.w.com">
<% ElseIf (GetDomainType() = "CA") Then %>
<meta HTTP-EQUIV="REFRESH" content="7; url=http://www.e.com">
<% End If %>
<!-- #INCLUDE file="mobile_sitefiles.asp"-->
<% If (GetDomainType() = "WRT") Then %>
<title>WRT</title>
<% ElseIf (GetDomainType() = "EL") Then %>
<title>EL</title>
<% ElseIf (GetDomainType() = "CA") Then %>
<title>Curb APeel</title>
<% Else %>
<title>Call</title>
<% End If %>
I've tried:
<% If (GetDomainType() = "CTH") Then
<meta HTTP-EQUIV="REFRESH" content="7; url=http://www.w.com">
ElseIf (GetDomainType() = "CA") Then
<meta HTTP-EQUIV="REFRESH" content="7; url=http://www.e.com">
End If %>
<!-- #INCLUDE file="mobile_sitefiles.asp"-->
<% If (GetDomainType() = "WRT") Then
<title>WRT</title>
ElseIf (GetDomainType() = "EL") Then
<title>EL</title>
ElseIf (GetDomainType() = "CA") Then
<title>Curb APeel</title>
Else
<title>Call</title>
End If %>
But then it just breaks the page.
Upvotes: 1
Views: 28
Reputation: 3854
As Lankymart commented, you can't mix html with asp like that. I'm not sure what you mean by "clean up" or "concise", but if you really, really want to waste your time refactoring working code, there are two things I'd suggest.
One, I don't know what GetDomainType
is doing, but regardless, it seems unnecessary to call it five times. Instead, call it once, assign the result to a variable, and do your branching on that variable.
Two, it's generally slightly more readable (and a teeny-tiny bit more efficient) to reduce the number of times you switch between asp and html.
Combining those two things, you'd get something like
<%
dim DomainType, url, title
DomainType = GetDomainType
If DomainType = "CTH" Then
url = "www.w.com"
ElseIf DomainType = "CA" Then
url = "www.e.com"
Else
url = ""
End If
Select Case DomainType
Case "WRT" title = "WRT"
Case "EL" title = "EL"
Case "CA" title = "Curb APeel"
Case Else title = "Call"
End Select
%>
<%If url <> "" Then%>
<meta HTTP-EQUIV="REFRESH" content="7; url=http://<%=url%>">
<% End If %>
<!-- #INCLUDE file="mobile_sitefiles.asp"-->
<title><%=title%></title>
Upvotes: 3