Page 1 of 1

Presenting the parsed HTML code in the browser...

Posted: Sat Aug 23, 2008 1:23 pm
by FresnoBob
Hi All,

This is not so much a syntax question - more advice as to how to approach the solution...

I'm writing a fairly simple script which enables the user to construct a menu for their website by choosing a variety of style attributes (colours, fonts, text alignment, etc). After generating the menu they should then be able to copy the code from the browser without having to go into the source. So essentially it's in 3 sections on screen...

1: A form presenting the various style options
2: The finished menu generated from the chosen options
3: The parsed HTML code and CSS for the generated menu (to then cut 'n' paste)

This all happens on the same page enabling the user to generate the menu and then change individual attributes and see the results as they go. Each change is effected by resubmitting the page - there is no client-side scripting.

The first two parts I have sorted - but I'm scratching my head as to how to tackle the third. I've got the script to generate the code so that the menu can be seen as a finished product in the browser but then I have to get it to generate the same code again (perhaps in a textarea field) for the user to copy from the browser.

Any suggestions?

Thanks in advance.

Bob.

Re: Presenting the parsed HTML code in the browser...

Posted: Sat Aug 23, 2008 3:17 pm
by jaoudestudios
Yes use a textarea to show unparsed code.

Re: Presenting the parsed HTML code in the browser...

Posted: Sat Aug 23, 2008 4:41 pm
by FresnoBob
Sorry - should have been clearer. Displaying the material isn't the problem - I need to know how to get hold of it.

What I need is page that displays three sections...

1: the form for choosing the style attributes of the menu
2: the finished menu itself
3: the HTML and CSS used to produce the menu

1 and 2 are fine - the scrip currently generates the HTML code in order to display the menu on the page - but how do I then get hold of the code to display it as raw text?

Since the script has to complete in order to accomplish stage 2, it seems to me that I have to generate the code for stage 3 in parallel - but I can't work out how to approach it.

Re: Presenting the parsed HTML code in the browser...

Posted: Sat Aug 23, 2008 4:52 pm
by jaoudestudios
How are you displaying the finished code? You must be echoing a variable, just use the same variable in the textarea.

Re: Presenting the parsed HTML code in the browser...

Posted: Sat Aug 23, 2008 8:50 pm
by FresnoBob
jaoudestudios wrote:How are you displaying the finished code? You must be echoing a variable, just use the same variable in the textarea.
No - the code used to produce the finished menu isn't a single variable. The form sets a series of variables within the embedded CSS. These have to be parsed in order to complete the second section. Clearly I need a way to capture this batch of code after it has been parsed so that I can deploy it at the end of the script.

What I'm looking for is advice as to how to approach this.

Thanks.

Re: Presenting the parsed HTML code in the browser...

Posted: Sun Aug 24, 2008 3:29 am
by jaoudestudios
I think you need to post some code! As I think you are over complicating it.

Do you use many echos? You could collect all the variables up into one and just use one echo at the end. Post some code and we can take a look.

Re: Presenting the parsed HTML code in the browser...

Posted: Sun Aug 24, 2008 9:12 pm
by FresnoBob
jaoudestudios wrote:Do you use many echos? You could collect all the variables up into one and just use one echo at the end. Post some code and we can take a look.
No - the code to produce the finished article is essentially a very long single string - a style sheet with the attributes set via many variables.

I have now enclosed this in a single function which I can now call as and when required.

Thanks for your input.