0

I have some code blocks that I include on every page: header.asp, footer.asp etc.

They exist under the subfolder /myincludes/ on my main domain.

So naturally I use the command

<!--#include virtual="/myincludes/header.asp"-->

on my pages to include them, and it works just fine.

The thing is, from time to time I want to change the subdirectory's name (to something like /myincludes2/)

But I'd prefer it if I wouldn't have to re-write all of the include virtual commands all over again.

I tried doing this:

<% thefolder="/myincludes2" %>
<!--#include virtual=thefolder&"/header.asp"-->
<!--#include virtual=thefolder&"/footer.asp"-->

But it just doesn't work.

3
  • SSI are evaluated before the ASP ISAPI extension is called so trying to add dynamic content is not going to work. This comes down to how you have structured the project more then anything else. If it helps you can create groups of #includes by placing them inside another #include file. Commented Oct 12, 2015 at 13:34
  • Hey thanks for the explanation @Lankymart but I don't see how groups of includes can me help me. Anyway, search and replace it is... Thanks again Commented Oct 12, 2015 at 14:09
  • For the time it will take to update your includes you could instead switch to using a root include with your various referenced includes. that way in future when you need to change again the process will be less time consuming. Commented Oct 12, 2015 at 14:34

1 Answer 1

2

Could you create a single file that is reference on every page such as:

<!--#include virtual="/root-includes.asp"-->

Then within this file have:

<!--#include virtual="/myincludes/header.asp"-->
<!--#include virtual="/myincludes/header.asp"-->

That way if you change the folder name you only have to reference it in one file. It also allows the use of further code (select case statement for example) to further manipulate the references to includes files. The only downside is an initial rewriting of the include path

*just seen @Lankymart answer which is the same as I suggested

Sign up to request clarification or add additional context in comments.

5 Comments

@Django This is what I was suggesting (thanks David for the attrib). Plus you can create multiple roots includes to handle your various different approaches.
Hey guys, thanks for the help. But I want some of the "inner" includes to appear later on the page (footer.asp will show only after the main content). So how will this "root" include help me to show the "inner" includes in their proper place on the page?
@Django That entirely depends on how you structure the header and footer includes. For example if they are a collection of functions then you can call those functions anywhere in your page and the include references can stay inside the root include. Just because you have an include doesn't mean you have to place it physically in the page where the content needs to appear, that is common because people don't wrap the logic in those includes in functions that can then be reused.
@Django Personally I use includes more like libraries of code rather then shortcuts to quickly dumb output to the screen. For example I would have a section.asp include defined at the top of the page (or inside a root include) that contained a procedure called say showSection(section) and I would call that inside the page and the point where I wanted to output my footer something like Call showSection(PAGE_FOOTER) where PAGE_FOOTER was a global constant stored in a constants include.
@Lankymart I see. I'll look up some actual examples to completely wrap my head around this. I know of this method being used in WP and other big CMSs but never have I seen it implemented in classic ASP. Thank you for all of the useful info!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.