Click to See Complete Forum and Search --> : changing path to templates


dvdljns
11-02-2006, 10:48 AM
I have some asp pages using templates. When this was built everything was dumped into one folder to make it easier I want to change the files into folders by extension. easy enough I thought. Is there a way I can build a inc file that will let the asp files know to look in the template folder for the templates. I have a include called comman maybe I could add something to this.

so_is_this
11-02-2006, 10:54 AM
If it were me, I would just bite the bullet and go change the actual references to the templates to point to the new folder/path. Keep in mind that you can use Server.MapPath() to help you with your references.

russell
11-02-2006, 11:06 AM
yes u can. this is one of the reasons to use include files -- so u can make sweeping changes in one place. now you'll need to go and include the file in all your asp files that need it though.

can also put path in application variable, but include is the way to go. if all pages are structured the same, you can do a massive search and replace to add the include directive to the top of all the files

dvdljns
11-02-2006, 12:08 PM
Ok. Bear with me both of you. Server.mappath is what I expected to find and change but it was not there. which made me relize there was more than one way to do it. Which got me to thinking. Since all the files was in one place by ext maybe I could get the app to look for all the html templates in one folder. here's what it looks like they did, sounds crazy to me but seems to work. They dumped all the files in one folder so they would not need to worry about path then wrote a sub in comman.asp to handle the new templates you might right. Here's the sub and usage.



Sub LoadTemplate(sPath, sName)
Dim nName
if not isObject(objFSO) then
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set DBlocks = Server.CreateObject("Scripting.Dictionary")
Set ParsedBlocks = Server.CreateObject("Scripting.Dictionary")
end if
if objFSO.FileExists(sPath) then
DBlocks.Add sName, objFSO.OpenTextFile(sPath).ReadAll
nName = NextDBlockName(sName)
while not (nName = "")
SetBlock sName, nName
nName = NextDBlockName(sName)
wend
end if
End Sub


' Usage:
' LoadTemplate server.mappath("/templates/new.html"), "main"
' SetVar "ID", 2
' SetVar "Value", "Name"
' Parse "DynBlock", False 'or True if you want to create a list
' Parse "main", False
' PrintVar "main"
'
This is from a common file loaded as an include on all pages. Is that an application variable. So to use that as an include I need to rewrite it as a function that way when it loads it will automatically load a path and I do not have to call a sub on every page. Am I understanding this right.

so_is_this
11-02-2006, 12:28 PM
By the way... I wasn't advocating to not use include files at all. Include files are definitely time-savers. What wasn't made clear (originally) was just what kind of references were being used and, therefore, what kind of changes would be required. It sounded like something "automatic" (read: "magic") was being asked for and there just isn't any such thing in ASP. So, it is possible I made some presumptions as to the matter at hand. ;)

dvdljns
11-02-2006, 01:48 PM
No! I just took it to mean that You think that was the best way to do it in this case. But maybe If I explain everything you will understand better. I decided asp was the way I wanted to write my webpage so I bought a book then learned that although it explains what the commands mean it really only helps you build an app in a general way. The web either keeps you writing hello world or gives you examples that has little to do with what you are trying to build or is over your head. So I started finding and downloading apps. I find the closest thing to what I want to do download it then how that person did it. Then when I want to do it all I have to do is recreate what I learned. I found A Portal that I like But have to understand it first. It uses templates which is an ideal new to me but I love. But he has everything dumped into one folder. Which causes a lot of confusion for me. I need it organized in a way I can understand then I can start working my way through this. But to my surprise I cannot evan figure how to get the asp files to find the templates and he did not do it in a way any of the tuterials show so I am trying to learn from scratch part of what I thought is example would teach me. But time is a factor. automatic? do not know but if I can get the path to set from an include maybe better.It does not mean that that I won't have to use mappath in my apps in the future but it sounds like a good way to handle bulk asp pages and I already have to load this as a include anyway. I just have to find someone will to teach me.

so_is_this
11-02-2006, 02:01 PM
Using the function you posted, I would certainly place that function in an include file. I would not expect that the call to that funciton also be in an include file. This is what I meant by biting the bullet and changing all the files in which you find a call to that function. The alternative, is to kludge up your function so that it has to examine the first argument and figure out where the referenced template now resides.

Of course, if all files referenced via that function *were* in the same folder and all those same files are to be *moved* to the same new folder, then perhaps changing the function is simpler. However, it would make it confusing if all the calls to that function didn't get changed because just looking at the call would not tell you where is the referenced file. You'd have to go check the function, too. I call that a programming nightmare.

dvdljns
11-02-2006, 04:49 PM
Ok! now I feel were getting someplace I think. We went from can this be done to two ways it can be done.

You'd have to go check the function, too. I call that a programming nightmare.

It would only be a nightmare to someone else. I know where they are, besides that is one of reasons I want do it this way. If you put all the asp files in a folder called asp and all the html templates in a folder called templates or whatever. then all you have to do is look at the ext.
how would I Implament that.

dvdljns
11-02-2006, 05:38 PM
This may be a little off topic but sounds something like what I am trying to do.
Would it help me.

There is no way to manipulate the path seen by IIS from asp code, that comes from windows only and not any .ini files. Simply use the common technique of setting a global variable, like in a session variable, that contains the path to files then concatenate that variable in all your file references.

what is he trying to say? [concatenate that variable in all your file references]

so_is_this
11-03-2006, 07:13 AM
So, let's say your original call looks like this:

LoadTemplate server.mappath("new.html"), "main"

If we leave that call unchanged, then you would just change your function to strip off everything that Server.MapPath added, add in the folder dictated by the file extension, and then re-apply Server.MapPath to the resulting path info.

dvdljns
11-03-2006, 07:40 AM
HUH! Here's what I am trying but cannot get it wrote right.

LoadTemplate server.mappath("/templates/") & "new.html"), "main"

I decided that If this sub will map the path to new template files then I should be able to get it to set the for all templates. I think later I may play around with doing it as aplication var. in global asa. But right now anyway I can get it to work. I also need to check with pws because I think they something like this with themes.
Whats wrong with that call as wrote I get an expected end error with it.

so_is_this
11-03-2006, 10:35 AM
This would be more correct -- if you're going to change the call:

LoadTemplate server.mappath("/templates/new.html"), "main"

dvdljns
11-03-2006, 01:39 PM
That's the same as the old call and does not work.

so_is_this
11-03-2006, 01:56 PM
Try this and tell me what you got for output:

Dim tmplt
tmplt = Server.MapPath("/templates/new.html")
Response.Write tmplt & "<br>" & vbCrLf
LoadTemplate tmplt, "main"

dvdljns
11-03-2006, 02:02 PM
Error Type:
Microsoft VBScript compilation (0x800A0400)
Expected statement
/workfolder/asp/Default.asp, line 22

so_is_this
11-03-2006, 02:27 PM
Which line is that?

dvdljns
11-03-2006, 02:47 PM
I fixed the error. what it does print out this line.

c:\inetpub\wwwroot\templates\new.html

dvdljns
11-03-2006, 02:54 PM
ok I spotted one thing I am doing wrong. my path is wrong.

dvdljns
11-03-2006, 03:22 PM
It is working. Thanks For the help here's the line that worked.

LoadTemplate server.mappath("\workfolder\templates\default.html"), "main"

so_is_this
11-03-2006, 07:38 PM
Salud!

dvdljns
11-08-2006, 11:54 AM
Ok! here's what I did. I pulled out the asp book and looked through my notes and here's what I came up with. I rewrote the main part of the webpage without the forum and all that other stuff. This is the way I know how to do it now.


Redirect = ""
TemplateFileName = "Default.html"
Set Events = CreateObject("Scripting.Dictionary")
PathToCurrentPage = "./"
FileName = "Default.asp"
PathToRoot = "./"
ScriptPath = Left(Request.ServerVariables("PATH_TRANSLATED"), Len(Request.ServerVariables("PATH_TRANSLATED")) - Len(FileName))
TemplateFilePath = Server.MapPath("./template/") & "\"
'End Initialize Page


If I understand it right the differance is the db, I do not need to use a database with this. on his default page he has something like get spath sname. I ran a search on saving path as a string, but I did not come up with anything. That is what the programer is doing right? Does anyone know of a website That will help me understand this. I could rewrite the whole website but it would be cobbed together with asp 2.0 and 3.0 Or if everybody is not tired of playing teacher by now could someone explain it to me.

so_is_this
11-08-2006, 02:09 PM
Not sure just what you're asking.

dvdljns
11-08-2006, 11:20 PM
Look at #4. I think that Is called by this line. LoadTemplate sAppPath & sTemplateFileName, "main" I am trying to learn how he did it so I can change the path..

dvdljns
11-09-2006, 08:34 AM
I can put the path in the way I wrote it but don't want to do that if path info is already there. In that case I need replace it instead of just more code. since it has a call LoadTemplate. The path is already defined somewhere as sAPPPATH.

RIGHT?

If I just keep adding code I will just end up with a huge app with a lot of useless code. Evan though it works It will be code heavy. Not only that I can not troubleshoot code I can not understand. Besides I do not want to just throw up someone elses app like it was my own. I can throw this on every page and get it to work.LoadTemplate server.mappath("\workfolder\templates\default.html"), "main" Changeing the default.html to whatever the page is, but that is not the way it is done. Doing that does not help my understanding. I guess what I am asking is does that code in post # 4 help define the path of the templates and if so will replaceing it with my code serve the same purpose. And do I need to save it as a string.

so_is_this
11-09-2006, 10:33 AM
If it were me, the only thing I would do differently than this:

LoadTemplate server.mappath("\workfolder\templates\default.html"), "main"

is to do this and put the call to MapPath into the function:

LoadTemplate "/workfolder/templates/default.html", "main"

Otherwise, I don't understand how doing it this way would not help your understanding.

dvdljns
11-09-2006, 01:28 PM
but how is he doing it. he is definatly doing something differant.

so_is_this
11-09-2006, 01:38 PM
Not really. He is just loading the template into storage so that you can apply the supplied functions and methods to that loaded template.

dvdljns
11-09-2006, 04:55 PM
Yes! it took me awhile but I finally saw it. Since he was dumping all the files in one folder he did not need to call the path just the pagename. So all I have to do is put my function in a common file so it will load the template path then call the template by name. DUH!!! Thanks for your help. I guess I was so sure he had done something clever, I just did not see what was in front of me.