Jump to content

Embedding variables within an include statement


Guest Lester
 Share

Recommended Posts

Guest Lester

I have an situation where a user has access to simple data files in a folder which they can edit on the fly. These are text content files for a "news" feature and I'd like to be able to pull them into a template file with an include statement.So we are faced with the old problem that you cannot place an ASP variable inside an Include Statement.ie. great if we could do this....<% fname="header.inc" %><!--#include file="<%=fname%>"-->Is there some way that the Include File statement could be built up as a text string and then executed as such without having to restate the variable.thanks .les.

Link to comment
Share on other sites

I have an situation where a user has access to simple data files in a folder which they can edit on the fly. These are text content files for a "news" feature and I'd like to be able to pull them into a template file with an include statement.So we are faced with the old problem that you cannot place an ASP variable inside an Include Statement.ie. great if we could do this....<% fname="header.inc" %><!--#include file="<%=fname%>"-->Is there some way that the Include File statement could be built up as a text string and then executed as such without having to restate the variable.thanks .les.
<%dim fnamefname = "header.asp"Server.Execute(fname)'remainder of page content goes here%>

Or optionally,

dim fnamefname = "some query"Server.Execute("page.asp?q=" & fname)

Server.Execute is not the same as an include file. An include basically pastes code from file file into another, then it executes all of that code inline as if it were one piece.Server.Execute doesn't work like that. It literally forces the server the make a new page request, then it copies the page output from that page request into your original page. That means you can't share variables between pages when you use Server.Execute.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...