VP-ASP :: Shopping Cart Software

Shopping Cart Software Solutions for anywhere in the World

US/Canada(Toll Free): +1 888 587 2278
Europe/UK: +44 (020) 7193 9408
Australia/New Zealand: +61 3 9016 4497

VP-Cart StoreFront Customer Forum

Home | Profile | Register | Active Topics | Members | Search | FAQ
Save Password
Forgot your Password?

 All Forums
 VPCart Forum
 General help me questions
 dynamically including files in templates
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Senior Member

United Kingdom
1898 Posts

Posted - May 05 2004 :  10:17:30  Show Profile  Visit devshb's Homepage  Reply with Quote
i can't find a way to do this, but i think it can be done somehow by using the right syntax (i've tried all the combinations that i can think of but no luck).....

in my product details page i want to optionally include an extra load of html towards the end of where the template is (eg to show sample screenshots and other additional info without having to go to another page)

ie i want to use the same template file for all my products, but i want to add an extra bit on the end for some products, and that extra bit will be specific per-product (and optional).

i don't want to use separate templates for each effected product as i'd end up with tons of duplicated template logic; i just want a specific bit of it to be included optionally/dynamically.

so, near the end of my tmp_product.htm template, i want to do something like:

$[INCLUDE pother1]

(where pother1 holds the filename i want to include, but can be blank)

does anyone know if this can be done, and if so do you know the syntax ?

Simon Barnaby
Freelance Developer
Java-E UK
[email protected]

VP-ASP New User

192 Posts

Posted - May 05 2004 :  13:08:29  Show Profile  Visit jonmadrid's Homepage  Reply with Quote
Hi Simon,

I think one of the things that may be giving you problems is trying to get the include file names to be dynamic -- That doesn't work unfortunately. I have come up with a solution for you that works right around that though. Its farily basic in principle but works just great. I've included step by step instructions to help you implement it. Here it goes:

Step 1:
Edit shopfileio.asp. At the end of the ProcessKeyword sub, around line 445 or so, look for this:

Handle_OitemDelivery value, parsearray, parseRS

and just place this after it:

rc= 0

Step 2:
Then, just below that part there is a line that looks like this:

end select
end sub

Add this chunk of code directly after that:

Sub Handle_AddHTMLFile
Dim htmlDB
Dim htmlSQL
Dim htmlRS
Dim htmlSTR
Dim htmlFIELD

'Specify which field in the product table you have your HTML file names in:
htmlFIELD = "pother1"

'Write out the SQL to get the info for this product:
htmlSQL = "SELECT " & htmlFIELD & " FROM products WHERE catalogid = " & catalogid

'Open the database:
ShopOpenDatabase htmlDB

'Create the Recordset
Set htmlRS = htmlDB.Execute(htmlSQL)

'If we have a record mathcing (which we should), and there is a file specified, then include it:
If NOT htmlRS.EOF Then
If htmlRS(htmlFIELD) <> "" Then
'Get the contents of the HTML file to include and pass them to the "strMain"
htmlSTR = getFileContents(htmlRS(htmlFIELD))

'Use the "Response" Object to "Write" the completed page to the client.
Response.Write htmlSTR
End If
End If

End Sub

Function getFileContents(strIncludeFile)
Dim objFSO
Dim objText
Dim strPage

'Instatiate FileSystem object:
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

'Make sure the file exists. If not, there's no sense in trying to open it:
If objFSO.FileExists(Server.MapPath(strIncludeFile)) <> True Then
getFileContents = ""
exit Function
End If

'Open the file into the Text Stream object:
Set objText = objFSO.OpenTextFile(Server.MapPath(strIncludeFile))

'Get contents and return as string:
getFileContents = objText.ReadAll

'Clean up after ourselves by closing object and freeing used resources:
Set objText = Nothing
Set objFSO = Nothing
End Function

Step 3
At the top of that last piece of code, there is an option to specify which field in the product table you have your HTML file names in. It's set to "pother1" in the code I have given here but all you need to do is change it there (just that one spot) to have it look in a different field.

Step 4
Save and upload shopfileio.asp

Step 5
Update your product records with the file names of the HTML files you want to include. If the files are in the same directory as the cart, there is no need to put a path: "/shop/myincludefile.htm". You can do just the file name "myincludefile.htm". If the files are outside the cart folder, you will need to put the path in for sure so it knows where to find the file.

Step 6:
Edit your product template file and add the following small bit of code wherever you want the HTML file to be included:


Step 7
Save and upload that template file.

That's it. You're done. That's all there is to it.

Now, a brief explanation of the logic behind this: You've added the call to your product page that tells it to look in the field you have specified (default is "pother1") for a file to include. If there is a value in the specified field, it first checks to see if the file exists since you might have mistyped the filename, or have something other than a filename in there. That check is included so that if the file happens to not exist the user won't get an ugly, page-halting error message.

Moving right along. Once the file is determined to exist, its contents are read in using the FileSystmeObject Text Stream and then output for the client. By doing all that we have dupliated the effect of "including" a file but have achieved it with dynamic file names which are read in from the product records. Not only that, but we know for sure the file exists as well before we try to include it.

I've tested this code and it appeared to work just fine for me. If you happen across any bugs though, let me know and I can fix them up. I hope this helps!

All the best,

Jon Madrid
Madrid Communications
Web Design, Development, and Hosting
Go to Top of Page

Senior Member

United Kingdom
1898 Posts

Posted - May 05 2004 :  17:23:31  Show Profile  Visit devshb's Homepage  Reply with Quote
cool; thanks for that, i really appreciate the time/effort you put into that reply/solution; i'll try it out.
thanks again.

Simon Barnaby
Freelance Developer
Java-E UK
[email protected]
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Snitz Forums 2000