Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP code in <#INCLUDE>

Status
Not open for further replies.

Microbe

Programmer
Oct 16, 2000
607
AU
Hey everyone,

I am trying to do something like this

<!--#include file=&quot;templates/<%=table.fields.item(&quot;value&quot;)%>&quot;>

However, it seems the include statement interprets the script literally as the error I get is:

The include file 'templates/<%=table.fields.item(' was not found.

Being able to do this would be a very very cool thing for the app I am working on.

For others and maybe put ideas in your head...I have created a &quot;top&quot; and &quot;bottom&quot; of a page and based on the value pulled from the db, would pull a include a specific file in the middle of the page.

It works beutifully if I hard code the include file, now I want it to be dynamic.

Maybe someone has another thought on how to do this.
Steve Davis
hey.you@hahaha.com.au
 
Microbe,

I's say the fact that you have the ASP inside the quotes if causing ASP to literally look for a the specified file. Try something like the following:

<%
Dim filename : filename = table.fields.item(&quot;value&quot;)

<!--#include file=filename>

%> Mise Le Meas,

Mighty :)
 
Microbe,

I forgot about the full path to the file:

<%
Dim filename : filename = &quot;templates/&quot; & table.fields.item(&quot;value&quot;)

<!--#include file=filename>
%>

I'm not sure if that is the correct syntax but you could try various combinations of the above. e.g.

<%
Dim filename : filename = &quot;templates/&quot; & table.fields.item(&quot;value&quot;)
%>

<!--#include file=<%=filename%>>


Mise Le Meas,

Mighty :)
 
or you could just response.write the whole line. :)

response.write(&quot;<!--#include file=&quot;&quot;templates/&quot; & table.fields.item(&quot;value&quot;) & &quot;&quot;&quot;>&quot;)

 
Thanks for the suggestions:

If I try Mighty's idea (which I had experimented with earlier) I get:

The include file '<%=filename%>' was not found. It is still taking it literally and not seeing it as ASP code.

Link9's only half works because the response.write pushes the code the the browser rather than interpreting it on the server and in the page source I can see <!--#include file='templates/1/filename.asp' --> rather than the included code.

There is one (awful) solution I would rather avoid, using <script runat=&quot;server&quot; src=&quot;filename&quot;></script>

Doing it this way would mean making all of the include file script. i.e. the whole include file would have to be built from response.write's rather than just having native html.

Ugly and hard to maintain.

I really appreciate both the suggestions, but had already tried tham and they don't work.

This is a tough one. I am not even sure it is possible.

Steve Davis
hey.you@hahaha.com.au
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top