Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bespoke HTML, CSS, JavaScript with CGI 4

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
I've been using PERL for many years and write all my HTML code by hand using a zillion backslashes.

On a few of my posts people have said "Why are you writing HTML, use the CGI module, you'll never have to write a line of HTML code again"

one claimed they write all theire CSS menu's, forms, webpages etc.. with the PERL CGI module.

can someone explain to me how, how can the CGI module know how to draw your menu, without you using HTML, this doesn't make any sense to me.

Can anyone help explain how all this is done with the CGI module without writing a single line of HTML?

Thanks 1DMF



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
You have to bear in mind that on sites like Tek-Tips
I was really thinking more along the lines of sites like not support / community forums.

I've been thinking long and hard over this re-write, I still don't understand how any template or CGI module will help, I have created an example RTF doc with a diagram and code to better explain, rather than using this text box.






"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
i've just read (well skipped through) the CPAN template module synopsis, I'm willing to give it a whirl, at least to understamnd its fundementals, that might give me a better understanding on how I can achieve some of my goals using the "Seperate you code" principle.

I was rather shocked to find I actually understood alot of what was written, which beleive me is a first for me & CPAN. only snag is has the file in a TAR, anyone know where I can get hold of the WINDOWS, version of this mdule.

thanks.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
also having read up a bit more it would seem the conundrum i've ben toying with is a standard one, and the info i was reading said, that is what PHP is all about, misng PERL & HTML.

however it mentions "Embperl" as the daddy to all posible solutions be it templating or PHP.

Has anyone got any advice or info regarding Embperl, is it a module? it says it is written in C, does that mean I would need to get my webhost compnay to install something , if they don't already support it?


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
OK, I'm not going to promise this works (I don't have a webserver available that's running Perl at the moment), but here's some code that runs with the HTML::Template module. I've used the code in your document as a starting point, so that should lend to it's familiarity for you.

Code:
#!/usr/bin/perl

use strict;
use HTML::Template;

############
# HomePage #
############

# Get Home Page SQL Records
my @rs = &getSQL("Home","*","1=1","Ord");

# Get Shouts
my @shout = &getSQL("Shouts","*","1=1","ID DESC");

$catlist .= &getMenu; #not sure what this sub does, but you'll need it.

############################ Loop Home Page 
# Set Switch
my $switch = 0;
my (@section_data, @shouts);

# Loop records
for(@rs) {
	#instantiate instance of the data
	my %data;

	# Add one to switch counter    
	$switch++;
	
	#add info to data set
	$data{'Title'} = $_->{'Title'};
	$data{'Info'} = $_->{'Info'};

	# Check switch for modulus of 2
	if(($switch % 2)) {
		#if not, tell template to end row
		$data{'end_row'} = 0;
	}
	else {
		$data{'end_row'} = 1;
	}

	push @section_data, \%data;
}  

############################## Loop Shouts
$switch=0;

for(@shout){
	$switch++;

	my %data;
	# Check switch for modulus of 2
	if(($switch % 2)) {
		#if not, tell template to use class 1
		$data{'class'} = 'shout1';
	}
	else {
		$data{'class'} = 'shout2';
	}
	
	$data{'Name'} = $_->{'SName'};
	$data{'Comment'} = $_->{'SComment'};

	push @shouts, \%data;
}
           
# Add Bottom Links
$catlist .= &getBLinks("STD");

my $template = HTML::Template->new(	type => 'filename',
															source => '/path/to/html/home.html',
															die_on_bad_params => 0) or die "Cannot open Home Template file: $!";

$template->param(	'section' => \@section_data,
								'shouts' => \@shouts );

print header;

print $template->output;

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>SSPL Home Page</TITLE>
<META NAME="KEYWORDS" CONTENT="underground, dance music, music, dance, underground music, dj, djs, electronica, computer music, clubbing, raves, rave, record, records, cd, cds, jungle, techno, drum, bass, house, hardcore, garage, hip hop"> 
<META NAME="DESCRIPTION" CONTENT="Dedicated to underground music enthusiasts, listen to tunes, order tunes, sign/view guestbook, play games, cool links, chat room, charts and votes system, listen to our radio or post messages to our message board discussion forum, love music?, if yes, why not visit our web site !!!">

<script type="text/javascript">

function bloc_clic()
{
	return false;

}

//-->

</script>
<SCRIPT language="JavaScript">

<!-- Begin
function movepic(img_name,img_src) {
document[img]name[/img].src=img_src;
}
// End -->

</SCRIPT>
</HEAD>

<BODY onContextMenu="return bloc_clic();" BGCOLOR="#000000">
<!-- Start Menu Template HTML -->
<tmpl_include name="./menu.html">
<!-- End Menu Template HTML -->
<table>
    <tr>
        <td class="title" bgproperties="stretch" >&nbsp;SSPL Home Page</td>
    </tr>
    <tr>
        <td><center>
	        <table border=0 class=table width="100%">
		        <tr>
		            <td class=table width="100%"><center>
		                    <table class=table2 cellpadding="3" cellspacing="3" width="100%">
		                        <tr>
		                            <td>
                                        <table width="100%" align=center>
											<tr>
											<tmpl_loop name="section">
												<td valign=top width=360>
													<table width="355" cellspacing=0 cellpadding=0 >
														<tr>
															<td class=title350 valign=middle>&nbsp;<tmpl_var name="Title"></td>
														</tr>
														<tr>
															<td valign=top><center>
																<table class=table350 height="255" cellpadding=5>
																	<tr>
																		<td class=table2 valign=top><tmpl_var name="Info"></td>
																	</tr>
																</table>
															</td>
														</tr>
													</table>
												</td>
											<tmpl_if name="end_row">
											</tr>
											<tr>
											</tmpl_if>
											</tmpl_loop>
										</table>
										<center><div id="shouts">
										<table>
											<tr>
												<td class=title700 colspan=2>&nbsp;THERE'S A SHOUT, GOING OUT, TO THE WORLD - CHECK IT OUT!</td>
											</tr>
												<td align=center valign=middle>
													<table class=table700 cellpadding=3 cellspacing=1 valign=middle>
														<tmpl_loop name="shouts">
														<tr>
															<td width=150 class="<tmpl_var name='class'>" valign=middle><tmpl_var name="Name"></td>
															<td valign=middle class="<tmpl_var name='class'>"><tmpl_var name="Comment"></td>
														</tr>
														</tmpl_loop>
													</table>
												</td>
											</tr>
										</table></div>
									</td>
								</tr>
							</table>                                                          
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
		<td>
			<!-- start bottom links addition -->
			<tmpl_include name="./bottom_links.html">
			<!-- end bottom links addition -->
		</td>
	</tr>
</table>
</body>
</html>

Some things to note:
[ul]
[li]I've added in some Included files to the HTML template. This allows you to keep one set of code for standard items in your site such as Menuing and Footer text. These will be snippets of HTML code that is pulled in when the template is parsed.[/li]
[li]I didn't have the code that pulls in the database information, so this could be trimmed a bit more I'm sure. Simply taking the code above and making it render in the sub routines would make this a bit more modular, but is not necessary.[/li]
[li]Adding in small thing such as error code is simple in this manner. Just add an include with the location of the error snippet and add in the appropriate template parameters to make it generate.[/li]
[/ul]

Hope this helps!

- George
 
To get the module, if you're on a Windows box, I'd suggest using PPM (Perl Package Manager) to download and install it. It will do all the work for you and makes it much easier than running the make files and such... You can access it by starting a command prompt and typing:

Code:
ppm install HTML-Template

- George
 
sorry , I can't "Install" modules, I do not host the install of PERL!

I need the module.pm so I can upload it to my area and use it that way, if it is possible.

Rieekan - thank you so much, once i've got the module, i can play with your example, to get a feel for the way it all bolts together.

I've been thinking again about 'embperl' i don't beleive I want this, it's not for separating your code, it's for embeding PERL into the HTML, the opposite of what i do (embed HTML in PERL), but still what i'm trying to break away from!


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Chief,

You might want to think about moving to a host that will let you install modules? Or buy your sysadmin a large bottle of scotch in exchange for the admin password ...

Just a thought ... ;-)
 
moving to a host that let's me install modules, that would make it a dedicated server hosting, we don't have that sort of money, we have shared hosting!

but the tech sup guys at our webhosting are a pretty good bunch, so maybe the latter will work :)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
You can attempt to install the module file directly to the server and add in the path to your lib (upon execution), but I'm not sure if it would do any good. There are some dependencies to this module (per the documentation and Makefile), so it may not work when installed.

I'd suggest working with your host to see if they will install this module. It's been around for a while and I've not come across a hosting company that really balked at installing something that was at least a full version release (HTML::Template is at version 2.7). If it helps, you can point them to the [link ]HTML::Template CVS[/url] on Sourceforge. I know it doesn't help with the immediate issue, but I wouldn't see why they wouldn't help by installing the module. It's kind of standard customer service if you ask me.

If they do, I'd take Paul's advice and get a new host. I know of a really good one here in the states that will install any module you ask for (again, at least a full version release is necessary). All you have to do is ask.

- George
 
1. They won't install any modules ive asked.
2. Changing host is not acceptable at present, to much work involved, plus I don't have the budget.
3. How do I open these darn GZ tar files.

on a side note, how much is this hosting your on about, plus the fact it's in the states is of no good to us, we're in the UK.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Hi

1DMF said:
3. How do I open these darn GZ tar files.
The most simple way is Total Commander. Some popular file compressors can handle it too ( I think WinRAR, but maybe WinZip or WinAce ).

Or try some project which develop/port Unix tools for Windows, like CygWin, GNUWin32, MinGW. One of them should have a [tt]tar[/tt] for Windows. If none of them help, you can also try googling.

Feherke.
 
I have winzip - I keep getting error with it.

Tryin Winrar - thanks.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
My hosting here breaks down to $6.95 a month paid once every two years. With that, I get a gig of disk space, 50 gigs of transfer a month, unused bandwidth rolls over to the next month, and a slew of other things...

I knew you were in the UK (URL kind of gave it away), which is why I specifically mentioned that it was a US hosting company.

WinZip should be able to open the gz file (I was able to download and open the one from CPAN). If you can't, it may be an issue with the installation.

- George
 
hey Rieekan,

My winzip didn't seem to like the tar file, I installed winrar and unziped it fine, only it doesn't contain the HTML::Template module, as you suggested, it requires you to run the makefile.pl locally on the install of PERL.

This is not an option for use currently, our webhost has declined installing "Bespoke" modules because it is shared hosting.

this is the only "downside" I have had with them, support is fantastic (plus i can call them as they are UK based).

is it possible for someone to provide me with the final .pm module that i could place locally in my webspace and include in the @INC, or will this not work.

This method is the only way I can use 3rd party modules not distributed as standard with the latest ActiveState PERL install.

regards,
1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
home_loan (at) hotmail (dot) com

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Thanks so much, I shall play with it over the next few days and come back if I have any problems, unfortunately, I have some other work i must tend to, before continuing my "self inflicted" regime of expanding my knowledge and doing things better.

For a start I have to re-build the bosses PC (I blew it up yesterday - d'oh [bomb] ) and now it needs a new mainboard.

boy was I popular! , personally i'd have throw the PC away long time ago it's a crappy Athlon XP 1733 mhz (2100), slow as you like compared to the other Intel P4 1600mhz machines we have.

But i guess a mainboard is cheaper then a new PC!

regards
1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Take your time. My boss has me working on supporting flash applications we didn't build right now, and I'm not a Flash developer, so my hands are full.

As for the mainboard problems, I know how you feel... I'm working on the same thing for my friend. It's funny how I always get wrapped into these things.

Anyway, feel free to post any questions you have. I've used HTML::Template quite extensively and can help where needed.

- George
 
I have tried my hardest to steer clear of Flash, I hated it years back, when it first came out, as you had to install a load of crap just for it to work and as most people had a modem, it made a website so slow, i'd leave if it had flash.

Nowadays it's really come into it's own, with the power of modern PC's and Broadband, so I thought I might bite the bullet and have ago, but then I discovered AJAX, so now there is no need ;-)

Good luck, and thanks again for your help so far.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top