I always end up never quite believing it when, once again, it dawns on me that I can’t complete a project the way I visualise due to ASP Classic’s lack of support for dynamic includes.
This time, I was creating a CMS-like site, which included mixed HTML/ASP files automatically. I tried pretty much every other solution — including server.execute (no go — doesn’t preserve variables/functions), and other examples of using ASP’s execute() command to parse files (didn’t work for mixed HTML/ASP).
So, the only thing left was to write my own. It’s fairly simple, and due to ASP/VBScript’s horribly limited feature set, very low-level. It steps through a file one character at a time, and decides if it is in “HTML mode” or “ASP mode” at an given time, and then uses this staus to convert the file into a set of executable lines.
It should handle most things correctly, with the exception of defines, and <!--#
-style directives. It handles short ASP write tags (<%= %>
) just fine. Variable scope is preserved inside the include file, and variables/functions set inside the include file continue to exist outside it after it is included — in other words, just as they should.
To use it, simply include the file, and use it just as you would in a sane language:
include("relative_path_to_local_file.asp")
The function returns false if the file doesn’t exist, or true otherwise.
If you fix any bugs in this, please let me have them.
Download it here: ASP Dynamic Includes
Hi,
Well thought out solution, but it’s not as simple as it could be. All the solutions I’ve seen to this problem go down the same route as yourself.
I developed an alternative technique to this problem which is a lot simpler and doesn’t have any code bloat, check it out on the link below:
http://www.aspmessageboard.com/showthread.php?t=229532
Hope you find it useful :o)
Very nice, thanks! Keep up the good work – it’s appreciated.
Wow. Thanks! So useful!
Hello, have you tried this alternate solution! http://www.codango.com/asp/fnc/content/?tree=aspin/tutorial/scriptin/serversi&id=10828910
This is a very good tip particularly to those fresh to the blogosphere.
Short but very precise information… Thank you for sharing this one.
A must read article!
Just wanna say thanks! Not much information on dynamic include for asp, but luckily stumbled upon yours. Saved me alot of headache.
hi, can you develop from zero or translate a php API to send whatsapp messages from asp classic?