Accessing/Passing an object variable to a Server.Execute Include

S

Sike

Hi everyone,

I've been browsing this and a few other related newsgroups trying to
get my head around this problem, and so far all the trails seem to go
cold, without an acceptable solution being reached. I'm posting here
because there seems to be a few MVP's knocking around, and if they dont
know, then it's a safe bet nobody does.

I'm beginning to think that what I want to do is simply not possible -
but i'll put it out there once more.

Here goes: I'm writing a content managaement system - and i'm making
use of dynamic includes via the "read a text file" technique, and then
substitiuting values into markers in the template.

For example. I have a text "template" file, that contains the html for
the dynamic page. Within the html text file are various markers that
are replaced at run time with statements such as:

myText = replace(myText, "##topnav##", topheader)

which works great. However, this substitution has to be hard coded
somewhere into the application. This is obviously suboptimal - as for
every new template I add, I need to write a specific "build" function
for that page's substitutions.

My planned work around, was to make the "build" function an asp page
that is Server.Executed when required....and making the build function
file editable through the CMS. Thus allowing me to edit the way the
page is built without editing core logic.

The problem is how I pass the variables to be substituted into the
template into the Server.Execute file. Here's the catch: I need to pass
Objects into the build file - specifically a dictionary object that
contains all the substitutions to be made.
i.e. obj.item( topheader ) = "this is the page header"
obj.item( phonenum ) = "017738393" etc.

I simply cant get this to work. I hope i've explained it clearly
enough. Anybody got any ideas?
One final question: Is it possible to specifiy a dynamic filename for
a Server.Execute?

i.e.
Dim fName
fName = "buildSalesPage.asp"
Server.Execute fName

Thanks for reading this ridiculously long post.
Hope somebody out there can offer a solution - or a work around. I'm
sure other CMS systems must have similar problems.

Thanks again.
Tony
 
A

Anthony Jones

Sike said:
Hi everyone,

I've been browsing this and a few other related newsgroups trying to
get my head around this problem, and so far all the trails seem to go
cold, without an acceptable solution being reached. I'm posting here
because there seems to be a few MVP's knocking around, and if they dont
know, then it's a safe bet nobody does.

I'm beginning to think that what I want to do is simply not possible -
but i'll put it out there once more.

Here goes: I'm writing a content managaement system - and i'm making
use of dynamic includes via the "read a text file" technique, and then
substitiuting values into markers in the template.

For example. I have a text "template" file, that contains the html for
the dynamic page. Within the html text file are various markers that
are replaced at run time with statements such as:

myText = replace(myText, "##topnav##", topheader)

which works great. However, this substitution has to be hard coded
somewhere into the application. This is obviously suboptimal - as for
every new template I add, I need to write a specific "build" function
for that page's substitutions.

My planned work around, was to make the "build" function an asp page
that is Server.Executed when required....and making the build function
file editable through the CMS. Thus allowing me to edit the way the
page is built without editing core logic.

The problem is how I pass the variables to be substituted into the
template into the Server.Execute file. Here's the catch: I need to pass
Objects into the build file - specifically a dictionary object that
contains all the substitutions to be made.
i.e. obj.item( topheader ) = "this is the page header"
obj.item( phonenum ) = "017738393" etc.

I simply cant get this to work. I hope i've explained it clearly
enough. Anybody got any ideas?
One final question: Is it possible to specifiy a dynamic filename for
a Server.Execute?

i.e.
Dim fName
fName = "buildSalesPage.asp"
Server.Execute fName

Thanks for reading this ridiculously long post.
Hope somebody out there can offer a solution - or a work around. I'm
sure other CMS systems must have similar problems.

Yes you can call server execute using a variable name to specify the path to
be executed.

As no doubt you have discovered putting an object into the session is a no
no.

However something which can behave much like a dictionary is an XML node and
it's attributes.
You can then assign the XML string to a session variable and reconstitute
the XML node in the server executed page:-

Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.loadXML "<root />"
Dim oDictNode : Set oDictNode = oDOM.documentElement

oDictNode.setAttribute("topheader") = "this is the page header"
oDictNode.setAttribute("phonenum") = "017738393"

Session("params") = oDOM.xml

Server.Execute "servicePages/service1.asp"



'servicePages/service1.asp
<%
Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.loadXML Session("params")
Dim oDictNode : Set oDictNode = oDOM.documentElement

myText = replace(myText, "##topnav##", oDOM.getAttribute("topheader"))


Having said that if you create an XML DOM you might as well take a look XSLT
which is designed to transform XML into output such as HTML. See:-

http://www.w3schools.com/xsl/xsl_languages.asp

However it might be overkill for what you need.

Anthony
 
S

Sike

Anthony said:
Yes you can call server execute using a variable name to specify the path to
be executed.

As no doubt you have discovered putting an object into the session is a no
no.

However something which can behave much like a dictionary is an XML node and
it's attributes.
You can then assign the XML string to a session variable and reconstitute
the XML node in the server executed page:-

Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.loadXML "<root />"
Dim oDictNode : Set oDictNode = oDOM.documentElement

oDictNode.setAttribute("topheader") = "this is the page header"
oDictNode.setAttribute("phonenum") = "017738393"

Session("params") = oDOM.xml

Server.Execute "servicePages/service1.asp"



'servicePages/service1.asp
<%
Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.loadXML Session("params")
Dim oDictNode : Set oDictNode = oDOM.documentElement

myText = replace(myText, "##topnav##", oDOM.getAttribute("topheader"))


Having said that if you create an XML DOM you might as well take a look XSLT
which is designed to transform XML into output such as HTML. See:-

http://www.w3schools.com/xsl/xsl_languages.asp

However it might be overkill for what you need.

Anthony

Thanks very much Anthony - your post have given me just the inspiration
i needed.

Top draw my friend.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top