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 sizbut 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 include a specific file in the middle of the page.

It works beautifully 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
 
Not 100% sure, but try replacing <!--#include file=&quot;templates/<%=table.fields.item(&quot;value&quot;)%>&quot;>
with:

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

I had a simalar problem pulling a bit of code containing a URL. Turned out I just needed to drop the quotes. Try it, can't hurt. ----------------------------------------
Don't forget to visit for some banging new music from DJ Cumback
 
Nice idea, but nogo...I even tried

<%
filename=&quot;templates/1/t1-1.asp&quot;
%>

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

and get

The include file '<%=filename%>' was not found.

both with and without quotes.

Tiis thread is also running in the ASP forum where there has been acouple of ideas that didn't work either.

I appreciate teh thought though.


Steve Davis
hey.you@hahaha.com.au
 
Try <!-- #include file='<%=filename%>' --> ~Javrix

A broken clock is correct twice per day.

A roomful of monkeys on typwriters will eventually write the great american novel.

If you gave an infinate number of rednecks, an infinate number of shotguns to shoot at an infinate number of stree
 
Thanks Javrix,

But I as I said, I had already tried it with both single and double quotes.

Maybe it just can't be done!? Steve Davis
hey.you@hahaha.com.au
 
What about without any quotes of any kind?
~Javrix

If you gave an infinate number of rednecks, an infinate number of shotguns to shoot at an infinate number of street signs, they would eventually write Romeo and Juliet in braille.
 
hehe...I appreciate your persistence...but I have tried that too.

Each time, it just interprets the <%...%> literally, doean't run the script at all. Steve Davis
hey.you@hahaha.com.au
 
I dunno what to tell you. I played with it a little bit, this is as close as I can get. When I view source, it all looks good, but it doesn't bring up the file:

Page 1 -

<HTML>
<BODY>
<FORM ACTION=&quot;results.asp&quot; METHOD=&quot;post&quot;>
<INPUT TYPE=&quot;radio&quot; NAME=&quot;form&quot; VALUE=&quot;1&quot;> 1
<BR>
<INPUT TYPE=&quot;radio&quot; NAME=&quot;form&quot; VALUE=&quot;2&quot;> 2
<BR>
<INPUT TYPE=&quot;submit&quot; VALUE=&quot;Go&quot;>
</BODY>
</HTML>


Page 2 -

<%@ Language=VBScript %>
<% dim form
form=Request.Form(&quot;form&quot;)
%>
<HTML>
<BODY>
<%
if form=&quot;1&quot; then
Response.Write &quot;<!-- #include file=&quot;&quot;&quot; & &quot;1.txt&quot; & &quot;&quot;&quot; -->&quot;
elseif form=&quot;2&quot; then
Response.Write &quot;<!-- #include file=&quot;&quot;&quot; & &quot;2.txt&quot; & &quot;&quot;&quot; -->&quot;
end if
%>
</BODY>
</HTML>

~Javrix

If you gave an infinate number of rednecks, an infinate number of shotguns to shoot at an infinate number of street signs, they would eventually write Romeo and Juliet in braille.
 
Hmmm...maybe I have hit the brick wall and found something that just can't be done.

I think I know why...my guess is that the <# include> line is processed b4 the ASP layer gets a look at the page. That way any script in the include file will be seen by the ASP engine.

it was a nice thought and would have been good to make work.
Steve Davis
hey.you@hahaha.com.au
 
I know why it doesn't work. An ASP code cannot be inside an HTML comment code. For example:

<!-- This is a comment code from <%=lastpage%> -->

Lastpage wouldn't work. I don't know why, but it just won't work.

Sorry. ~Javrix

If you gave an infinate number of rednecks, an infinate number of shotguns to shoot at an infinate number of street signs, they would eventually write Romeo and Juliet in braille.
 
I've just done the same bloody thing!!!

Here your solution:
I had to solve this problem by adding the content of the two include file to a seperate table in a database. Set 'CONTENT1', 'CONTENT2', 'CONTENT3', ect feilds, then code this above the <head> your page.

<%
strvar_content = &quot;0&quot;
If Request.Form = &quot;option1&quot; then strvar_content = Recordset1.Fields.Item(&quot;CONTENT1&quot;)
If Request.Form = &quot;option2&quot; then strvar_content = Recordset1.Fields.Item(&quot;CONTENT2&quot;)
If Request.Form = &quot;option3&quot; then strvar_content = Recordset1.Fields.Item(&quot;CONTENT3&quot;)
If strvar_content = &quot;0&quot; then strvar_contact = &quot;ERROR MESSAGE&quot;
%>

And bang this in the page <%=strvar_content%>

Hope that helps

----------------------------------------
Don't forget to visit for some banging new music from DJ Cumback
 
YUKKKK!!!

I would certainly work, but it is an ugly way to do what I am doing.

My app is to enable people to choose their own template for viewing webpage layout so it gets the content from the db, but lays it out according to their chosen style.

What I wanted to do was build the top and bottom parts of the viewable page and then include the definable part of the body based on a value from a db.

To have to pull code from a db would make it pretty hard to edit, though it is not impossible

Having said all that, it is a good solution to the problem in some circumstances. Steve Davis
hey.you@hahaha.com.au
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top