For Programmers: Free Programming Magazines  


Home > Archive > ASP > October 2006 > Accessing/Passing an object variable to a Server.Execute Include









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

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

2006-10-30, 6:58 pm

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

Anthony Jones

2006-10-30, 6:58 pm


"Sike" <tony.dillon@gmail.com> wrote in message
news:1161092780.733827.44490@h48g2000cwc.googlegroups.com...
> 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



Sike

2006-10-30, 6:58 pm


Anthony Jones wrote:
> "Sike" <tony.dillon@gmail.com> wrote in message
> news:1161092780.733827.44490@h48g2000cwc.googlegroups.com...
>
> 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.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com