Re: embedding a CGI script in a HTML page?
On Mon, Dec 15, 2008 at 1:48 PM, Adam Jimerson wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Mike Williams wrote: > > > Your first question was: > > > I'm sorry I guess I should have been more specific in my question, I > never wanted to try and put perl code ino my HTML page, I know that that > is impossible because the browser has no clue what to do with it, what I > am asking about is embedding the text/html the CGI.pm generates into a > page where I do have my style at. > This is a confusing statement. If you want to generate the output with a cgi program, the cgi program has to generate *all* of the output. Having the cgi program generate all of the output, and having it use your style sheet can resolve your problem. > >> I have the page generated by my CGI script inside another page that is > >> using my CSS. I've tried to have my CGI script directly handle my CSS > >> but it didn't work due to its limited support for CSS. So now I'm > >> trying to find a better way to make my CGI script look like the rest of > >> my site, I'm guessing this is what Template Toolkit if I can figure out > >> how to do it, or if my solution is the best. > > > > Are you using CGI.pm? > > > > If so, you can use css by adding: -style=>{'src'=>'/mystyle.css'} to > > the aguments of start_html: > > print $q->start_html(-style=>{'src'=>'/mystyle.css'}); > > > > This will cause your cgi code to use the stylesheet. > > > > I have tried that and when I tried to call up a div object, in my css > (is attached) called leftcolumn, instead of getting a navy blue column > on the left side of the page it is just white. > Did you perhaps use 'div class='leftcolumn' ? That will not work with your stylesheet. div id='leftcolumn' *will* work Here is a little cgi program that uses CGI.pm and your style sheet to print a some stuff in a blue column on the left side of the screen: #!/usr/bin/perl use warnings; use strict; use CGI; my $q = CGI->new(); print $q->header(), $q->start_html(-title=>"list msg test", -style=>{'src'=>'/css/se.css'}), ''; for (my $i = 1; $i < 26; $i++) { print $q->br("blue column line $i"); } print '', $q->end_html(); > No I am letting CGI.pm generate the HTML for me, I figured that it would > be the easiest way to do it. > > > > > Template toolkit is a very useful and powerful tool, but it is > > probably overkill if all you want to do is use stylesheets. You can > > do lots of other things with Template::Toolkit that may make it worth > > the time is takes to learn how to use it. For example, having header > > and footer information that appears on all of the pages on your site > > in a template, allowing you to make one change to the template and > > have that effect your entire site. You can also use template toolkit > > to generate static pages, so you can use templates to generate pages > > that do not require cgi, and re-used those templates in you cgi > > scripts. > > > > - From what I see in the tutorial, > > http://template-toolkit.org/docs/tutorial/Web.html#section_Dynamic_Content_Generation_Via_CGI_Script > , > the Templete Toolkit only outputs information from the script, but I > need it to handle input as well, my script I am working on is a > guestbook so it needs to get the name of the guest and a message then > output it, as well as save it to a log for later use by the script. > Everything works but the plain white background is ugly and doesn't > match the rest of my site which is why I started this thread. > You seem to be under the mistaken impression that you cannot get input using CGI.pm or Template::Toolkit. That is incorrect, either of those tools allow you to generate forms that can be used to get input from the user. If you look at perldoc CGI the very first screen contains an example of how to generate a form. Hope this helps, Mike
Re: embedding a CGI script in a HTML page?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Mike Williams wrote: > Your first question was: > >> Is it possible to embed a CGI scrip into a HTML page? > > Now you say: > >> I'm not trying to put perl code into the page > > You will get better answers if you start with clearer questions. > I'm sorry I guess I should have been more specific in my question, I never wanted to try and put perl code ino my HTML page, I know that that is impossible because the browser has no clue what to do with it, what I am asking about is embedding the text/html the CGI.pm generates into a page where I do have my style at. >> I have the page generated by my CGI script inside another page that is >> using my CSS. I've tried to have my CGI script directly handle my CSS >> but it didn't work due to its limited support for CSS. So now I'm >> trying to find a better way to make my CGI script look like the rest of >> my site, I'm guessing this is what Template Toolkit if I can figure out >> how to do it, or if my solution is the best. > > Are you using CGI.pm? > > If so, you can use css by adding: -style=>{'src'=>'/mystyle.css'} to > the aguments of start_html: > print $q->start_html(-style=>{'src'=>'/mystyle.css'}); > > This will cause your cgi code to use the stylesheet. > I have tried that and when I tried to call up a div object, in my css (is attached) called leftcolumn, instead of getting a navy blue column on the left side of the page it is just white. > If you are not using CGI.pm please specify what other module(s) you > are using, or if you are just generating the html yourself (not > recommended). > No I am letting CGI.pm generate the HTML for me, I figured that it would be the easiest way to do it. > > Template toolkit is a very useful and powerful tool, but it is > probably overkill if all you want to do is use stylesheets. You can > do lots of other things with Template::Toolkit that may make it worth > the time is takes to learn how to use it. For example, having header > and footer information that appears on all of the pages on your site > in a template, allowing you to make one change to the template and > have that effect your entire site. You can also use template toolkit > to generate static pages, so you can use templates to generate pages > that do not require cgi, and re-used those templates in you cgi > scripts. > - From what I see in the tutorial, http://template-toolkit.org/docs/tutorial/Web.html#section_Dynamic_Content_Generation_Via_CGI_Script, the Templete Toolkit only outputs information from the script, but I need it to handle input as well, my script I am working on is a guestbook so it needs to get the name of the guest and a message then output it, as well as save it to a log for later use by the script. Everything works but the plain white background is ugly and doesn't match the rest of my site which is why I started this thread. > Mike -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iEYEARECAAYFAklGpmQACgkQRMKiLy/EUZSx0wCfXwliS0Vfx/4/+fWdaCbtn/hu rCAAn0LB9YeTJ9oZSc5dJV+MX7kEWqzd =kr4k -END PGP SIGNATURE- body { margin:0; padding:0; line-height: 1.5em; } b { font-size: 110%; } em { color: red; } h5 { color : #ff; } #topsection { background: #fff; height: 90px; /*Height of top section*/text-align: center; } #topsection h1 { margin: 0; padding-top: 15px; } #contentwrapper { float: left; width: 100%; } #contentcolumn { margin-left: 210px; /*Set left margin to LeftColumnWidth*/ } #leftcolumn { position: absolute; top: 0; left: 0; width: 210px; /*Width of left column*/ height: auto; overflow: auto; background-color: #80; color: #fff; } #leftcolumn a { color : #FF; padding-left: 20px; } #footer { clear: left; width: 100%; background: #80; color: #00; text-align: center; padding: 4px 0; } #footer a { color: #80; } .innertube { margin: 10px; /*Margins for inner DIV inside each column (to provide padding)*/margin-top: 0; }-- To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org For additional commands, e-mail: beginners-cgi-h...@perl.org http://learn.perl.org/
Re: embedding a CGI script in a HTML page?
On Monday 15 December 2008 3:50:24 am Adam Jimerson wrote: > Dermot Paikkos wrote: > >> -Original Message- > >> > >>> http://www.template-toolkit.org/ > >>> > >>> Mike > >> > >> Looking at the website and the documentation, still reading through > > > > it, > > > >> I'm still not sure how to mix this with my CGI scripts to make them > >> look > >> like the rest of the site even though Konqueror supports the > >> tag, which I would think would be the last browser to support it. It > >> may just be that I'm new to CGI so I'm having to take what I am > >> learning > >> and throw it out the window? > > > > I am not sure TT is what you want. > > > > If you want to run perl code from within a html tags that's not possible > > as far as I know. You could use Greg's suggestion of > > http://perl.apache.org/embperl/ or use AJAX to call your perl cgi > > scripts. But if you insist that you want to put you code in the page > > then you really want ?php > > > > Dp. > > I'm not trying to put perl code into the page, they way I have it now is > I have the page generated by my CGI script inside another page that is > using my CSS. I've tried to have my CGI script directly handle my CSS > but it didn't work due to its limited support for CSS. So now I'm > trying to find a better way to make my CGI script look like the rest of > my site, I'm guessing this is what Template Toolkit if I can figure out > how to do it, or if my solution is the best. if you decide to go with a template system , a good simple one I use quite a lot is the module HTML::Template . this allows you to have separate html template pages with place holder tags that your CGI script would process and then output to the calling browser. You could then just take your regular html page with your css stuff applied and replace those bits that have to have a calculation or other function with a template var. you then can maintain the look of your static pages with your dynamically generated pages . Greg -- To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org For additional commands, e-mail: beginners-cgi-h...@perl.org http://learn.perl.org/
Re: embedding a CGI script in a HTML page?
Adam Jimerson wrote: I'm not trying to put perl code into the page, they way I have it now is I have the page generated by my CGI script inside another page that is using my CSS. I've tried to have my CGI script directly handle my CSS but it didn't work due to its limited support for CSS. So now I'm trying to find a better way to make my CGI script look like the rest of my site, I'm guessing this is what Template Toolkit if I can figure out how to do it, or if my solution is the best. I've going to cover some basics here, so I apologise if its starting too low for you. When a browser requests a URI, the server gets the content of that URI from somewhere and sends it back. It might get it from a file, it might get it from somewhere else. In the case of CGI, it runs a program and returns that instead. You need to edit the Perl program that is being called using CGI so it outputs the HTML that you want. (Including the to the stylesheet you are using, there is no problem with support for CSS, since when is output is just HTML, that is comes from a program rather than a file isn't relevant). We've no idea what method the program is currently using to determine what HTML is generated, so we can't tell you what needs to be done to edit it. What we can tell you is that using Template-Toolkit is a good approach when it comes to writing this kind of system. When using TT the general approach is to: (1) Gather up all the data you want into a Perl hash (2) Tell TT to process a template using that data TT then goes over the template (which might look something like: http://github.com/dorward/axford/tree/master/root/default.tt (sorry, its got a lot of legacy cruft in it, I'm in the process of cleaning it up) and replaces placeholders with the data (and has things to loop over arrays when you have repeated data). -- David Dorward http://dorward.me.uk/ -- To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org For additional commands, e-mail: beginners-cgi-h...@perl.org http://learn.perl.org/
Re: embedding a CGI script in a HTML page?
On Mon, Dec 15, 2008 at 7:50 AM, Adam Jimerson wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Dermot Paikkos wrote: >>> -Original Message- http://www.template-toolkit.org/ Mike >>> Looking at the website and the documentation, still reading through >> it, >>> I'm still not sure how to mix this with my CGI scripts to make them >>> look >>> like the rest of the site even though Konqueror supports the >>> tag, which I would think would be the last browser to support it. It >>> may just be that I'm new to CGI so I'm having to take what I am >>> learning >>> and throw it out the window? >> Your first question was: > Is it possible to embed a CGI scrip into a HTML page? Now you say: > I'm not trying to put perl code into the page You will get better answers if you start with clearer questions. > I have the page generated by my CGI script inside another page that is > using my CSS. I've tried to have my CGI script directly handle my CSS > but it didn't work due to its limited support for CSS. So now I'm > trying to find a better way to make my CGI script look like the rest of > my site, I'm guessing this is what Template Toolkit if I can figure out > how to do it, or if my solution is the best. Are you using CGI.pm? If so, you can use css by adding: -style=>{'src'=>'/mystyle.css'} to the aguments of start_html: print $q->start_html(-style=>{'src'=>'/mystyle.css'}); This will cause your cgi code to use the stylesheet. If you are not using CGI.pm please specify what other module(s) you are using, or if you are just generating the html yourself (not recommended). If you are generating the html directly in your perl code, you can insert a stylesheet reference between the and tags just as you do in a plain html page. Template toolkit is a very useful and powerful tool, but it is probably overkill if all you want to do is use stylesheets. You can do lots of other things with Template::Toolkit that may make it worth the time is takes to learn how to use it. For example, having header and footer information that appears on all of the pages on your site in a template, allowing you to make one change to the template and have that effect your entire site. You can also use template toolkit to generate static pages, so you can use templates to generate pages that do not require cgi, and re-used those templates in you cgi scripts. Mike -- To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org For additional commands, e-mail: beginners-cgi-h...@perl.org http://learn.perl.org/
Re: embedding a CGI script in a HTML page?
On Sun, Dec 14, 2008 at 10:01 PM, Adam Jimerson wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Mike Williams wrote: >> On Sun, Dec 14, 2008 at 1:28 PM, Adam Jimerson wrote: >>> On Dec 12, 12:47 pm, sdav...@mail.nih.gov (Sean Davis) wrote: >>> >>> Are you talking about this, >>> http://search.cpan.org/~abw/Template-Toolkit-2.20/lib/Template.pm? >>> If so it doesn't really say what it is for I am completely lost in how >>> to use it for my needs. >>> >> >> Take a look at the template toolkit web site, that may help you understand >> it. >> >> http://www.template-toolkit.org/ >> >> Mike > > Looking at the website and the documentation, still reading through it, > I'm still not sure how to mix this with my CGI scripts to make them look > like the rest of the site even though Konqueror supports the > tag, which I would think would be the last browser to support it. It > may just be that I'm new to CGI so I'm having to take what I am learning > and throw it out the window? Unfortunately, you'll probably just have to work through some of the examples to see how it helps you. As with much of perl, there are many ways to do it. I think, though, that many folks have thought about the problem of producing HTML from perl scripts and found that templating is the way to go. Also, you might want to look at a solution like CGI::Application that does much of the busy-work of writing CGI applications for you and enforces the MVC concept by design. Sean -- To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org For additional commands, e-mail: beginners-cgi-h...@perl.org http://learn.perl.org/
Re: embedding a CGI script in a HTML page?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dermot Paikkos wrote: >> -Original Message- >>> http://www.template-toolkit.org/ >>> >>> Mike >> Looking at the website and the documentation, still reading through > it, >> I'm still not sure how to mix this with my CGI scripts to make them >> look >> like the rest of the site even though Konqueror supports the >> tag, which I would think would be the last browser to support it. It >> may just be that I'm new to CGI so I'm having to take what I am >> learning >> and throw it out the window? > > I am not sure TT is what you want. > > If you want to run perl code from within a html tags that's not possible > as far as I know. You could use Greg's suggestion of > http://perl.apache.org/embperl/ or use AJAX to call your perl cgi > scripts. But if you insist that you want to put you code in the page > then you really want ?php > > Dp. > > I'm not trying to put perl code into the page, they way I have it now is I have the page generated by my CGI script inside another page that is using my CSS. I've tried to have my CGI script directly handle my CSS but it didn't work due to its limited support for CSS. So now I'm trying to find a better way to make my CGI script look like the rest of my site, I'm guessing this is what Template Toolkit if I can figure out how to do it, or if my solution is the best. -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iEYEARECAAYFAklGUpAACgkQRMKiLy/EUZRK7ACeIcy38u969ZbcgskecP4ru0db 8f0AnAqaRRqhj8r5sW4aeClU2TBoxAf9 =Zzkr -END PGP SIGNATURE- -- To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org For additional commands, e-mail: beginners-cgi-h...@perl.org http://learn.perl.org/
RE: embedding a CGI script in a HTML page?
> -Original Message- > > > > http://www.template-toolkit.org/ > > > > Mike > > Looking at the website and the documentation, still reading through it, > I'm still not sure how to mix this with my CGI scripts to make them > look > like the rest of the site even though Konqueror supports the > tag, which I would think would be the last browser to support it. It > may just be that I'm new to CGI so I'm having to take what I am > learning > and throw it out the window? I am not sure TT is what you want. If you want to run perl code from within a html tags that's not possible as far as I know. You could use Greg's suggestion of http://perl.apache.org/embperl/ or use AJAX to call your perl cgi scripts. But if you insist that you want to put you code in the page then you really want ?php Dp. -- To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org For additional commands, e-mail: beginners-cgi-h...@perl.org http://learn.perl.org/
Re: embedding a CGI script in a HTML page?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Mike Williams wrote: > On Sun, Dec 14, 2008 at 1:28 PM, Adam Jimerson wrote: >> On Dec 12, 12:47 pm, sdav...@mail.nih.gov (Sean Davis) wrote: >> >> Are you talking about this, >> http://search.cpan.org/~abw/Template-Toolkit-2.20/lib/Template.pm? >> If so it doesn't really say what it is for I am completely lost in how >> to use it for my needs. >> > > Take a look at the template toolkit web site, that may help you understand it. > > http://www.template-toolkit.org/ > > Mike Looking at the website and the documentation, still reading through it, I'm still not sure how to mix this with my CGI scripts to make them look like the rest of the site even though Konqueror supports the tag, which I would think would be the last browser to support it. It may just be that I'm new to CGI so I'm having to take what I am learning and throw it out the window? -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iEYEARECAAYFAklFyJQACgkQRMKiLy/EUZRbKwCfTwPTp0k8ka7h8GxYte5w3/N4 1VEAoJWT9hcdJnLOY+P9qZr0hacuK80C =gdo5 -END PGP SIGNATURE- -- To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org For additional commands, e-mail: beginners-cgi-h...@perl.org http://learn.perl.org/
Re: embedding a CGI script in a HTML page?
On Sun, Dec 14, 2008 at 1:28 PM, Adam Jimerson wrote: > On Dec 12, 12:47 pm, sdav...@mail.nih.gov (Sean Davis) wrote: >> >> You cannot put perl in a webpage the way that you do with PHP. >> However, there are a number of template engines written for and in >> perl that give you similar features. Take a look at Template Toolkit, >> as an example. >> >> Sean > > Are you talking about this, > http://search.cpan.org/~abw/Template-Toolkit-2.20/lib/Template.pm? > If so it doesn't really say what it is for I am completely lost in how > to use it for my needs. Have a look at: http://template-toolkit.org/ The goal of using a "template language" is to remove all those ugly print statements from your code. Instead, you use the template system to write HTML with a few extra tags in it that can use data that is passed into it to dynamically change parts of it. The main idea, though, is to separate your code (the part that does the database calls, validation, etc.) from the display of the results; the two are nearly orthogonal concerns. Sean -- To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org For additional commands, e-mail: beginners-cgi-h...@perl.org http://learn.perl.org/