Link to home
Start Free TrialLog in
Avatar of Treder
Treder

asked on

response.write and include file?

Hi,

I am trying to adapt a script which was originally used to see if an image name matches a variable within a specific folder, if it does then the image is displayed, if not then a default image is displayed.  I need to do a similar thing, but this time I am displaying different (html) text.  I thought about doing it with the html text in little include asp files but I am not sure if it works with the script.  Could someone take a look for me and advise.

<%
' See if there is a brand string in var level2 and that matches a brand description

Set fs=Server.CreateObject("Scripting.FileSystemObject")

if prodrs("p_level2") <> "" then
  if fs.fileexists(server.mappath("includes/" & server.urlencode(prodrs("p_level2")) & ".asp")) then
   response.write "<!-- #INCLUDE FILE=""includes/" & server.urlencode(prodrs("p_level2")) & ".asp"">"
else
   response.write "<!-- #INCLUDE FILE=""includes/default.asp"">"
end if
else
  response.write "<!-- #INCLUDE FILE=""includes/default.asp"">"
end if

set fs=nothing
%>

Many thanks,
Tony

Avatar of WMIF
WMIF

that will not work because includes are processed by the server before the asp code is processed.  depending on what is in the pages, it may work to do something like this.  the first one wont work though because of the asp code in the include statement

<%
' See if there is a brand string in var level2 and that matches a brand description

Set fs=Server.CreateObject("Scripting.FileSystemObject")

if prodrs("p_level2") <> "" then
  if fs.fileexists(server.mappath("includes/" & server.urlencode(prodrs("p_level2")) & ".asp")) then
%>
<!-- #INCLUDE FILE=""includes/" & server.urlencode(prodrs("p_level2")) & ".asp"">  <-------  no worky
<%
else
%>
<!-- #INCLUDE FILE=""includes/default.asp"">
<%
end if
else
%>
<!-- #INCLUDE FILE=""includes/default.asp"">
<%
end if

set fs=nothing
%>
Avatar of Treder

ASKER

Many thanks for the reply.

Yes, I read up a bit about the include processing.  Will give it a go and report back
Avatar of Treder

ASKER

I guess I could do something like this:

...
if prodrs("p_level2") = "producta" then %>

<td> product a text </td>

<%
else if prodrs("p_level2") = "productb" then
%>

<td> product b text </td>

<%
else
%>

<td> default text </td>

<%
end if


Would that be sensible??
set fs=nothing
%>
ASKER CERTIFIED SOLUTION
Avatar of Dany Balian
Dany Balian
Flag of Lebanon image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
please note that in your case you have one missing end if

the syntax of if statements is:

if condition then
'statement1
elseif condition2 then     'else and if are attached together no space between them
'statement2
elseif condition3 then
'statement3
else
'statement 4
end if

cheers,

dan
Avatar of Treder

ASKER

Dear hongjun,

Either you guys are ultra-tidy or I am a bit slack...  I have not yet had a chance to look at all the suggested solutions, which of course I need to do before I can allocate points appropriately.

I am sorry to the posters if they feel I have taken too long and I really appreciate the ideas put forward.

I will allocate points now based on a brief run through.

Many thanks all,
Tony
Avatar of Treder

ASKER

Sorry - that will teach me... In my haste I thought this was the cleanup of a newer post.  

... please ignore my previous post.