Technical Discussion
  >> Web Design / HTML / Web hosting Forum


Register (or login) on our website and you will not see this ad.


These posts have been archived and can no longer be replied to or modified.
  Print Thread
Standard User cheshire_man
(experienced) Wed 16-Jun-10 21:54:06
Print Post

How do I use functions to generate mark-up on the client?


[link to this post]
 
I'm putting together a free-standing CD containing a hard copy of sermon recordings from our church web site. It's visual format is very similar to the web site itself.

Because there's a lot of repetitive stuff with only slight differences, on the web site I use PHP functions to create the repeated HTML and function parameters to define the small differences. It all works fine.

On the CD, which needs to be capable of running on as many PCs and Macs as possible, I can't use PHP to generate the repetitive HTML. Can Javascript be so used? Any examples to, for example, create code along these lines?

Text
1
23
45
67
89
1011
1213
1415
1617
1819
2021
2223
2425
2627
<tr>
        <td class="sermon bold" width="8%">Date</td>        <td width="3%">&nbsp;</td>
        <td class="sermon bold" width="43%">Morning Service</td>        <td width="3%">&nbsp;</td>
        <td class="sermon bold" width="42%">Evening Service</td>        <td width="1%">&nbsp;</td>
</tr><tr>
        <td><hr class="light_gray" align="left"></td>        <td>&nbsp;</td>
        <td><hr class="light_gray" align="left"></td>        <td>&nbsp;</td>
        <td><hr class="light_gray" align="left"></td>        <td>&nbsp;</td>
</tr><tr class="sermon_b1">
        <td class="sermon color_ser" valign="top">13<span class="ordinal">th</span> June</td>        <td class="sermon color_ser" valign="top" align="center">
                <a href="sermons/ah_20100613am.mp3"><img src="images/speaker_bl.jpg" alt="Download sermon. Preacher: Phil Highton. Preacher: Phil Highton" title="Download sermon. Preacher: Phil Highton. Preacher: Phil Highton" border="0"></a>        </td>
        <td class="sermon color_ser" valign="top">Psalm 73: 27-28</td>        <td class="sermon color_ser" valign="top" align="center">
                <a href="sermons/ah_20100613pm.mp3"><img src="images/speaker_bl.jpg" class="va_zero" alt="Download sermon. Preacher: Dave Walker" title="Download sermon. Preacher: Dave Walker" border="0"></a>        </td>
        <td class="sermon color_ser" valign="top">Matthew 11:16-24</td></tr>

I'm certain it's by no means elegant code, but it works!

Thanks in anticipation

Tony
Standard User deleted
(deleted) Wed 16-Jun-10 22:50:08
Print Post

Re: How do I use functions to generate mark-up on the client


[re: cheshire_man] [link to this post]
 
I am confident that javascript can do what you want, although I am not good enough with the language to give you some sample code without spending more time and effort than I can afford right now.

However, you say you want the disk to be usable in as many PC's as possible. If I recall correctly IE's default behaviour is to not allow javascript to run from a source such as a CDROM.

Is there any reason why you cannot simply generate the different pages and save them individually on the disk and use relative linking to get from one to the other?
Standard User deleted
(deleted) Wed 16-Jun-10 23:02:48
Print Post

Re: How do I use functions to generate mark-up on the client


[re: deleted] [link to this post]
 
The OP could create an HTML Application as it can use javascript, vbscript and can execute commands.

-edit
[censored] sorry didn't notice that you needed it to run on a mac too.

Edited by deleted (Wed 16-Jun-10 23:05:11)


Register (or login) on our website and you will not see this ad.

Standard User deleted
(deleted) Wed 16-Jun-10 23:15:04
Print Post

Re: How do I use functions to generate mark-up on the client


[re: cheshire_man] [link to this post]
 
On the CD, which needs to be capable of running on as many PCs and Macs as possible, I can't use PHP to generate the repetitive HTML.

No reason not to (assuming the content of the final page is static). You just need to put the output of the PHP script on the CD rather than the PHP file itself. A couple of possible ways to do this are:
  • Upload the project to somewhere on your webserver where it won't get in the way of the main website (subdirectory or subdomain) and then run a program like wget to crawl over the pages saving a local copy that you can burn to CD.
  • Install the CLI version of PHP (i.e. not as part of a webserver) on your computer then you can run your scripts and save the generated HTML to a file.

Seeing as you've put the effort in to write the PHP code for the website it seems a waste not to use it for the CD too.
Standard User deleted
(deleted) Thu 17-Jun-10 09:30:00
Print Post

Re: How do I use functions to generate mark-up on the client


[re: cheshire_man] [link to this post]
 
http://creativebits.org/cross_platform_autorun_cd_cr...

The above might help.

Personally I'd just use the statically generated html code from the website so someone just browses them and chooses one. Relative links should be ok. I assume you have a show all sermons listing so you could use that.
Standard User cheshire_man
(experienced) Thu 17-Jun-10 21:42:35
Print Post

Re: How do I use functions to generate mark-up on the client


[re: cheshire_man] [link to this post]
 
Thanks for all the suggestions. I do indeed have the code as generated on the server and have used that.

What I was trying to do was to avoid repetition in the code on the CD. And the nuisance when you decide you want to change something and have to change the same line of mark up in 20 different places.

I've also been sent some code which I quite like which creates an array and populates a <div> which is populated with the concatenated array elements:

Text
1
23
45
67
89
1011
1213
1415
1617
1819
2021
2223
2425
2627
2829
3031
3233
3435
36
The following demonstrates the ability to generate a bunch of HTML
statements, and then insert them into a DIV at runtime.The use of an Array in buildContent is an optimisation : rather than
concatenating strings it builds an array then uses the "join" method togenerate a string which for large chunks of HTML is quicker. Hopefully
you can customise this to your needs... have fun :) 
<html><head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"type="text/javascript"></script>
</head><body>
<div id="content"></div>
<input type="button" id="changehello" value="hello"> <input type="button" id="changegoodbye" value="goodbye"> 
<script type="text/javascript">$(document).ready(function() {
    buildContent('initial content');    
    $('#changehello').click(function() { buildContent('hello'); });    $('#changegoodbye').click(function() { buildContent('goodbye'); }); });
 function buildContent(name) {
    var dynamicHtmlAsArray = new Array();    for (var i=0; i<5; i++) {
        dynamicHtmlAsArray[i] = name + "<br/>";    }
    var dynamicHtml = dynamicHtmlAsArray.join("");    $('#content').html(dynamicHtml);
} 
</script></body>
</html>

The pages already use a static copy of jQuery so that doesn't present a problem.

I'll look at all these thoughts and see what's what.

Thanks again guys

Tony
Standard User Deadbeat
(knowledge is power) Thu 17-Jun-10 23:53:46
Print Post

Re: How do I use functions to generate mark-up on the client


[re: cheshire_man] [link to this post]
 
I have (I think I still have it anyway) a small app here somewhere that is purposely built for what you're trying to achieve. It generates tight HTML etc with a CD front end that is cross platform. I'll scan through my archives tomorrow and see if I can dig it out for you.
Standard User deleted
(deleted) Sun 20-Jun-10 19:40:38
Print Post

Re: How do I use functions to generate mark-up on the client


[re: cheshire_man] [link to this post]
 
xsl/xml can do this.
  Print Thread

Jump to