Instead if you're handling all your pages this way in this process class you can take over RouteRequest() and put whatever is in ShowPage there. You can override that method and just copy that code into your process class. Most of the code in that method has to do with the Web Control framework which you can leave alone or throw out since you don't use it.
and you can hook your code into there.
The end result then will be that you can just SomePage.psp instead of ShowPage.psp?page=SomePage.psp, which is much more natural both from the URL and handling of the code.
Looking at the code in RouteRequest() that code sure could use some factoring :-)
Hi Thierry,
I am by no means a seasoned WebConnect developer but this thread caught my attention because I'm doing something similar. If I'm heading down the wrong path on this, hopefully someone will point out the flaw in my thinking.
In the site I am working on, almost all pages are displayed via a Process method called "ShowPage".
http://localhost/mySite/showpage.psp?page=somepage
The page name passed in the querystring is also the file name of the template file - in this case, "somepage.wc".
The ShowPage method looks something like this...
FUNCTION ShowPage(tcPage)LOCAL lcPage, lcTemplateFile, llContinue, lcTitleIF NOT EMPTY(m.tcPage)
lcPage = m.tcPageELSE
lcPage = REQUEST.QueryString("PAGE")ENDIF
lcPage = LOWER(JUSTSTEM(m.lcPage))
lcTemplateFile = ADDBS(THIS.cTemplatesPath) ;
+ ADDBS(THIS.cLanguage) + m.lcPage + ".wc"IF NOT FILE(m.lcTemplateFile)THIS.FileNotFound(m.lcTemplateFile)RETURNENDIF
llContinue = .T.
DOCASECASE m.lcPage = "this"
lcTitle = "Title for THIS page"CASE m.lcPage = "that"
llContinue = THIS.Authenticate() IF m.llContinue
lcTitle = "Title for THAT page"ENDIFCASE m.lcPage = "another"
lcTitle = "Title for ANOTHER page"OTHERWISE
lcTitle = CON_DEFAULTTITLEENDCASEIF m.llContinueLOCAL lcCSS, lcScriptsPRIVATE pcHeader, pcMenu, pcFooter
lcCSS = THIS.GetCSS(m.lcPage)
lcScripts = THIS.GetScriptsHead(m.lcPage)
pcHeader = THIS.GetHeader(m.lcTitle, m.lcCSS, m.lcScripts)IF NOT EMPTY(m.pcHeader)
pcMenu = THIS.GetMenu(m.lcPage)IF NOT ISNULL(m.pcMenu)
lcScripts = THIS.GetScriptsBody(m.lcPage)
pcFooter = THIS.GetFooter(m.lcPage, m.lcScripts)IF NOT ISNULL(m.pcFooter)
Response.ExpandTemplate(m.lcTemplateFile)ENDIFENDIFENDIFENDIFENDFUNC
Each of the "Get" methods builds an HTML fragment according to the page being displayed. These fragments are assigned to PRIVATE MEMVARS in the .WC template file.
My basic template file looks like this...
<!DOCTYPE html><htmllang="en"><%= pcHeader %><body><%= pcMenu %>><divclass="wrapper"><br /><divclass="container">></div>></div>>><%= pcFooter %></body></html>
I design a static HTML file in Visual Studio Express Web with the Header, Menu and Footer hard-coded. Once I have the appearance the way I want it, I copy the HTML content from between the WRAPPER/CONTAINER tags into the bare bones template above, insert any other <%= variables %> as needed, and Save As the final template.
I also use other small HTML fragments stored in separate text files.
For example, here is the GetMenu() method...
FUNCTION GetMenu(tcPage)LOCAL lcTemplateFile
tcPage = LOWER(JUSTSTEM(m.tcPage))DOCASECASE m.tcPage = "login"RETURN""OTHERWISE
lcTemplateFile = ADDBS(THIS.cTemplatesPath) ;
+ ADDBS(THIS.cLanguage) + "mainmenu.wc"ENDCASEIF NOT FILE(m.lcTemplateFile)THIS.FileNotFound(m.lcTemplateFile)RETURN .NULL.ENDIFLOCAL lcMenuClass, lcTemplateText, lnPos1, lnPos2, lcStringIF"lookup" $ m.tcPage
lcMenuClass = "navbar navbar-default navbar-lookup-top"ELSE
lcMenuClass = "navbar navbar-default navbar-fixed-top"ENDIF
lcTemplateText = FILETOSTR(m.lcTemplateFile)
lnPos1 = ATC(m.tcPage,m.lcTemplateText)IF m.lnPos1 > 0
lcString = [<li class="dropdown]
lnPos2 = RATC(m.lcString,LEFT(m.lcTemplateText,m.lnPos1))
lcTemplateText = STUFF(m.lcTemplateText,m.lnPos2 + LEN(m.lcString),0," active")ENDIF
lcTemplateFile = ADDBS(THIS.cTemplatesPath) ;
+ ADDBS(THIS.cLanguage) ;
+ IIF(EMPTY(THIS.cAuthenticatedUser), ;"loginmenu.wc","accountmenu.wc")
lcAcctMenuText = FILETOSTR(m.lcTemplateFile)
lcTemplateText = TEXTMERGE(m.lcTemplateText,.T.)RETURN m.lcTemplateTextENDFUNC
Again, if my approach is asking for trouble, I hope that someone will point it out.
If it gives you any ideas, that's cool.
Carl
Hi,
Starting to move a wConnect site from HTML-in-prg style to scripting style (.ExpandTemplate() and/or .ExpandScript() and/or template script-mapped extension).
Purpose: easily share existing HTML with a design agency, and easily integrate new HTML
Wondering how to share HTML code blocks across pages
eg, considering this block of HTML stored in head.htm
<!DOCTYPE html><htmllang="fr"><head><title><%=variable%></title>
....</head>
1/ how to make sure all pages in site include this block?
SSI directives are very handy because supported by all web servers
a typical SSI directive is:
>
Does wConnect support SSI directive?
2/ what is the best practice to make sure 'variable' is available when page is generated?
- use a 'private' variable (.ExpandTemplate() and/or .ExpandScript())
- move all code generating variable into a code block inside head.htm?
Also looking for wConnect user feedback/advice/tricks ...
Thanks,