html-template-users Mailing List for HTML::Template (Page 8)
Brought to you by:
samtregar
You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(42) |
Jul
(80) |
Aug
(77) |
Sep
(97) |
Oct
(65) |
Nov
(80) |
Dec
(39) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(63) |
Feb
(47) |
Mar
(45) |
Apr
(63) |
May
(67) |
Jun
(51) |
Jul
(78) |
Aug
(37) |
Sep
(45) |
Oct
(59) |
Nov
(50) |
Dec
(70) |
2004 |
Jan
(23) |
Feb
(90) |
Mar
(37) |
Apr
(53) |
May
(111) |
Jun
(71) |
Jul
(35) |
Aug
(58) |
Sep
(35) |
Oct
(35) |
Nov
(35) |
Dec
(20) |
2005 |
Jan
(51) |
Feb
(19) |
Mar
(20) |
Apr
(8) |
May
(26) |
Jun
(14) |
Jul
(49) |
Aug
(24) |
Sep
(20) |
Oct
(49) |
Nov
(17) |
Dec
(53) |
2006 |
Jan
(12) |
Feb
(26) |
Mar
(45) |
Apr
(19) |
May
(19) |
Jun
(13) |
Jul
(11) |
Aug
(9) |
Sep
(10) |
Oct
(16) |
Nov
(17) |
Dec
(13) |
2007 |
Jan
(9) |
Feb
(12) |
Mar
(28) |
Apr
(33) |
May
(12) |
Jun
(12) |
Jul
(19) |
Aug
(4) |
Sep
(4) |
Oct
(5) |
Nov
(5) |
Dec
(13) |
2008 |
Jan
(6) |
Feb
(7) |
Mar
(14) |
Apr
(16) |
May
(3) |
Jun
(1) |
Jul
(12) |
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
(9) |
2009 |
Jan
(9) |
Feb
|
Mar
(10) |
Apr
(1) |
May
|
Jun
(6) |
Jul
(5) |
Aug
(3) |
Sep
(7) |
Oct
(1) |
Nov
(15) |
Dec
(1) |
2010 |
Jan
|
Feb
|
Mar
|
Apr
(9) |
May
|
Jun
|
Jul
(5) |
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
(3) |
Mar
|
Apr
(28) |
May
|
Jun
|
Jul
(3) |
Aug
(4) |
Sep
(3) |
Oct
|
Nov
(8) |
Dec
|
2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
(2) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(2) |
Dec
|
2016 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
From: Alex T. <al...@ac...> - 2008-03-20 06:19:59
|
I completely agree. Unfortunately I've inherited a lot of the code and it needs to support all charsets. :( On Thu, 20 Mar 2008 14:31:54 +1100, Mathew Robertson wrote > Have you tried using utf8 as the encoding? You will get far more > millage out of utf8 than using entities. > > regards, > Mathew > > Alex Teslik wrote: > > Hello, > > > > I'm developing an app where there are some strings that have HTML entities > > in them, such as: > > > > This is a "Tést" > > > > These strings need to go into a template that is displayed in the iso-8859-1 > > character set. These strings need to be html escaped so that the quotes don't > > break things. When I put it in a template: > > > > <tmpl_var name="sentence" escape="html"> > > > > I get: > > > > This is a "&#233;st" > > > > Doh. The entity got squashed. > > > > So the easy way out is "just decode the entity before dropping it in the > > template"... but if the decoded entity cannot be displayed in iso-8859-1 when > > it is decoded, as is the case with a Chinese character like 我, than I'm > > out of luck and must pass the entity through to the template. But then I can > > no longer do all my escaping in the template. > > > > So I propose that the HTML::Template escaping does not squash HTML entities. > > Something like (quick off the cuff): > > > > sub entity_safe_escape { > > my $t=shift; > > > > $t=~s/&#(\d\d\d+);/ESCAPE_UNICODE_$1/g; > > $t=~s/&/ESCAPE_AMP/g; > > > > $t=~s/"/"/g; > > $t=~s/</</g; > > $t=~s/>/>/g; > > > > $t=~s/ESCAPE_AMP/&/g; > > $t=~s/ESCAPE_UNICODE_(\d\d\d+)/&#$1;/g; > > > > return($t); > > } > > > > How do others typically get around this problem? > > > > Thanks, > > Alex > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by: Microsoft > > Defy all challenges. Microsoft(R) Visual Studio 2008. > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > > _______________________________________________ > > Html-template-users mailing list > > Htm...@li... > > https://lists.sourceforge.net/lists/listinfo/html-template-users > > |
From: Mathew R. <mat...@ne...> - 2008-03-20 03:32:19
|
Have you tried using utf8 as the encoding? You will get far more millage out of utf8 than using entities. regards, Mathew Alex Teslik wrote: > Hello, > > I'm developing an app where there are some strings that have HTML entities > in them, such as: > > This is a "Tést" > > These strings need to go into a template that is displayed in the iso-8859-1 > character set. These strings need to be html escaped so that the quotes don't > break things. When I put it in a template: > > <tmpl_var name="sentence" escape="html"> > > I get: > > This is a "&#233;st" > > Doh. The entity got squashed. > > So the easy way out is "just decode the entity before dropping it in the > template"... but if the decoded entity cannot be displayed in iso-8859-1 when > it is decoded, as is the case with a Chinese character like 我, than I'm > out of luck and must pass the entity through to the template. But then I can > no longer do all my escaping in the template. > > So I propose that the HTML::Template escaping does not squash HTML entities. > Something like (quick off the cuff): > > sub entity_safe_escape { > my $t=shift; > > $t=~s/&#(\d\d\d+);/ESCAPE_UNICODE_$1/g; > $t=~s/&/ESCAPE_AMP/g; > > $t=~s/"/"/g; > $t=~s/</</g; > $t=~s/>/>/g; > > $t=~s/ESCAPE_AMP/&/g; > $t=~s/ESCAPE_UNICODE_(\d\d\d+)/&#$1;/g; > > return($t); > } > > How do others typically get around this problem? > > Thanks, > Alex > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users > |
From: Karen <kar...@gm...> - 2008-03-20 03:24:39
|
On 3/19/08, Alex Teslik <al...@ac...> wrote: > But then I can no longer do all my escaping in the template. Well, you're effectively handing it a half-escaped string. That's kind of a special case. > So I propose that the HTML::Template escaping does not squash HTML entities. That would break its behavior for me - I'm handing it unescaped strings, which (being somewhat self-referential discussions of HTML and CSS) very often contain examples of HTML entities, which H::T properly escapes so they are displayed the way the author expects them to be. It's not terribly helpful if, for example, someone says "To display an ampersand on the page, use '&'" and the forum displays "use '&'". An alternate escaping method would be fine, but changing the default behavior to kinda-sorta escape things, but not always, would IMHO be a Really Bad Thing. |
From: Alex T. <al...@ac...> - 2008-03-20 03:02:28
|
Hello, I'm developing an app where there are some strings that have HTML entities in them, such as: This is a "Tést" These strings need to go into a template that is displayed in the iso-8859-1 character set. These strings need to be html escaped so that the quotes don't break things. When I put it in a template: <tmpl_var name="sentence" escape="html"> I get: This is a "&#233;st" Doh. The entity got squashed. So the easy way out is "just decode the entity before dropping it in the template"... but if the decoded entity cannot be displayed in iso-8859-1 when it is decoded, as is the case with a Chinese character like 我, than I'm out of luck and must pass the entity through to the template. But then I can no longer do all my escaping in the template. So I propose that the HTML::Template escaping does not squash HTML entities. Something like (quick off the cuff): sub entity_safe_escape { my $t=shift; $t=~s/&#(\d\d\d+);/ESCAPE_UNICODE_$1/g; $t=~s/&/ESCAPE_AMP/g; $t=~s/"/"/g; $t=~s/</</g; $t=~s/>/>/g; $t=~s/ESCAPE_AMP/&/g; $t=~s/ESCAPE_UNICODE_(\d\d\d+)/&#$1;/g; return($t); } How do others typically get around this problem? Thanks, Alex |
From: Brad B. <bm...@ma...> - 2008-03-14 12:50:45
|
Well, it looks like Allen is in fact telling the browser which encoding to use, both in the header and the document. I think he is trying to figure out why he has to set it to UTF-8 when he believes the text is in gb2312. I believe that perl is printing the text as UTF-8 because it isn't being told otherwise. Regards, -- Brad On Fri, Mar 14, 2008 at 8:11 AM, Dawid Joubert <djs...@gm...> wrote: > Hi Allen, > > You can tell the browser what encoding to use for an HTML document. The > first way is to use HTTP Response headers by providing the right > Content-Type header example: > Content-Typetext/html; charset=UTF-8 > > The second way is to include it in the HTML document itself as a meta tag > > <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"> > <head> > <title>Accomodation</title> > * <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/> > * > </head> > > You should be doing the above anyway as it does not rely on any browser > defaults and UTF-8 is the way forward as it does not limit the character > set. > > > Regards > David > > > ----- Original Message ----- > *From:* Allen Zhang <act...@gm...> > *To:* htm...@li... > *Sent:* Friday, March 14, 2008 9:06 AM > *Subject:* [htmltmpl] Help! Chinese character displaying problem > usingHTML::TEMPLATE > > Hi all, > > My cgi script using Html::Template having some error display Chinese > Character. > I have set character set to gb2312, and the encoding character set was > set to gb2312 too. > But in that case, the "你好" wasn't displayed as expected. > However, I found that if I change the encoding character set of my * > browser* to utf8, it displays perfectly. > Why ? > Most browsers in China were set to gb2312 encoding, I don't want users > to manually change their > default setting to view my page. > What can I do? > Thanks!! > > > cgi code: > ################################################## > #!/usr/bin/perl -w > > use CGI::Carp qw(fatalsToBrowser); > use CGI qw(:standard); > use HTML::Template; > > my $template = HTML::Template->new(filename => 'title.tpl.php'); > my $title = '你好'; > $template->param('title' => $title); > *print header(-charset=>"gb2312");* > > print $template->output; > > template code: > ################################################## > <html> > <head> > <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> > <meta name="description" content=""> > <meta name="keywords" content=""> > <title><TMPL_VAR NAME=title></title> > </head> > <body> > <TMPL_VAR NAME=title> > <br> > Hello! > <br> > Hard code你好 > </BODY> > </HTML> > > > > Allen Zhang > > ------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > > ------------------------------ > > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users > > |
From: Brad B. <bm...@ma...> - 2008-03-14 12:45:32
|
Hello Allen, You say this: - "I have set character set to gb2312," - "the encoding character set was set to gb2312" But in your cgi code, I don't see any of these: - use Encode; - decode(... - encode(... - open FH ">:encoding(... - use open ':encoding(... So it looks like you aren't telling perl which encoding to use. I'm not an encoding expert by any stretch, but I think that in the absence of your telling perl which encoding to use, it is falling back on UTF-8 (but I'd expect you to see 'wide character' warnings, so maybe I'm wrong). This may be why it looks okay when you set your browser to UTF-8. How to fix? As I said, I'm no expert. If I were you, I'd start reading here: http://perldoc.perl.org/perlunitut.html and follow all the links until it starts to make sense (I'm currently in the process of doing that--again--myself). Hope that helps (hope I'm at least partly correct), -- Brad On Fri, Mar 14, 2008 at 5:06 AM, Allen Zhang <act...@gm...> wrote: > Hi all, > > My cgi script using Html::Template having some error display Chinese > Character. > I have set character set to gb2312, and the encoding character set was > set to gb2312 too. > But in that case, the "你好" wasn't displayed as expected. > However, I found that if I change the encoding character set of my * > browser* to utf8, it displays perfectly. > Why ? > Most browsers in China were set to gb2312 encoding, I don't want users > to manually change their > default setting to view my page. > What can I do? > Thanks!! > > > cgi code: > ################################################## > #!/usr/bin/perl -w > > use CGI::Carp qw(fatalsToBrowser); > use CGI qw(:standard); > use HTML::Template; > > my $template = HTML::Template->new(filename => 'title.tpl.php'); > my $title = '你好'; > $template->param('title' => $title); > *print header(-charset=>"gb2312");* > > print $template->output; > > template code: > ################################################## > <html> > <head> > <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> > <meta name="description" content=""> > <meta name="keywords" content=""> > <title><TMPL_VAR NAME=title></title> > </head> > <body> > <TMPL_VAR NAME=title> > <br> > Hello! > <br> > Hard code你好 > </BODY> > </HTML> > > > > Allen Zhang > > |
From: Dawid J. <djs...@gm...> - 2008-03-14 12:11:59
|
Hi Allen, You can tell the browser what encoding to use for an HTML document. The first way is to use HTTP Response headers by providing the right Content-Type header example: Content-Typetext/html; charset=UTF-8 The second way is to include it in the HTML document itself as a meta tag <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Accomodation</title> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/> </head> You should be doing the above anyway as it does not rely on any browser defaults and UTF-8 is the way forward as it does not limit the character set. Regards David ----- Original Message ----- From: Allen Zhang To: htm...@li... Sent: Friday, March 14, 2008 9:06 AM Subject: [htmltmpl] Help! Chinese character displaying problem usingHTML::TEMPLATE Hi all, My cgi script using Html::Template having some error display Chinese Character. I have set character set to gb2312, and the encoding character set was set to gb2312 too. But in that case, the "你好" wasn't displayed as expected. However, I found that if I change the encoding character set of my browser to utf8, it displays perfectly. Why ? Most browsers in China were set to gb2312 encoding, I don't want users to manually change their default setting to view my page. What can I do? Thanks!! cgi code: ################################################## #!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard); use HTML::Template; my $template = HTML::Template->new(filename => 'title.tpl.php'); my $title = '你好'; $template->param('title' => $title); print header(-charset=>"gb2312"); print $template->output; template code: ################################################## <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta name="description" content=""> <meta name="keywords" content=""> <title><TMPL_VAR NAME=title></title> </head> <body> <TMPL_VAR NAME=title> <br> Hello! <br> Hard code你好 </BODY> </HTML> Allen Zhang ------------------------------------------------------------------------------ ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ ------------------------------------------------------------------------------ _______________________________________________ Html-template-users mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/html-template-users |
From: Allen Z. <act...@gm...> - 2008-03-14 09:06:54
|
Hi all, My cgi script using Html::Template having some error display Chinese Character. I have set character set to gb2312, and the encoding character set was set to gb2312 too. But in that case, the "你好" wasn't displayed as expected. However, I found that if I change the encoding character set of my * browser* to utf8, it displays perfectly. Why ? Most browsers in China were set to gb2312 encoding, I don't want users to manually change their default setting to view my page. What can I do? Thanks!! cgi code: ################################################## #!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard); use HTML::Template; my $template = HTML::Template->new(filename => 'title.tpl.php'); my $title = '你好'; $template->param('title' => $title); *print header(-charset=>"gb2312");* print $template->output; template code: ################################################## <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta name="description" content=""> <meta name="keywords" content=""> <title><TMPL_VAR NAME=title></title> </head> <body> <TMPL_VAR NAME=title> <br> Hello! <br> Hard code你好 </BODY> </HTML> Allen Zhang |
From: Mathew R. <mat...@ne...> - 2008-02-24 23:39:26
|
Hi Ronald, >>> I am looking to generate easy visualizations of >>> objects serialized in a database USING the underlying model. >> It sounds like you're talking about a glue between "model" components >> like dbix::class, class::dbi, etc? >> > Close. Yes a glue layer between HTML::Template and a database. I > could try to use some of these higher layer abstractions (including > Rose:DB) or use a modern DBI layer with its > primay_key/primary_key_info/foreign_key_info functions ... Based on your example below, are you thinking of something like Template::Plugin::DBI (as used in Template::Toolkit)? ie: see examples here: http://search.cpan.org/~abw/Template-DBI-2.64/lib/Template/Plugin/DBI.pm Alternatively, have you looked at HTML::FillInForm? > <html> > <head><title>Test Template</title> > <body> > <TMPL_LOOP NAME="+books"> > <ul> > <li />Title is "<TMPL_VAR NAME=".title">" > <li />ISBN is <TMPL_VAR NAME=".isbn"> > <li />Authors are: > <ul> > <!-- name below is shorthand for +books.book_id.authors --> > <!-- could still be abbreviated to +authors if fk's link > tables --> > <TMPL_LOOP NAME=".book_id.authors:ORDER_BY:.last_name,.first_name" > > <li /><TMPL_VAR NAME=".last_name">, <TMPL_VAR > NAME=".first_name"> > </TMPL_LOOP> > </ul> > </ul> > </TMPL_LOOP> > </body> > </html> If so, (IMO) H::T wasn't designed to be pluggable/extensible in that way. However, that hasn't stopped a number of users extending/modifying the H::T codebase in various ways, ie: I use a version which allows me to subclass H::T (or H::T::E) so that I can extend the tag syntax. From memory, I think someone else on this list has hooked together H::T and HTML::FillInForm. In your example above, I would subclass H::T to handle the following (or something similar): ... <TMPL_SQL_LOOP NAME="books"> ...<TMPL_FIELD NAME="title"> ...<TMPL_SQL_LOOP NAME="authors" WHERE="book_id = books.book_id" ORDER_BY="last_name, first_name"> ...<TMPL_FIELD last_name>... ...</TMPL_SQL_LOOP> </TMPL_SQL_LOOP> ... cheers, Mathew |
From: Ronald S. <ron...@so...> - 2008-02-23 19:14:00
|
Mark Fuller wrote: > On Sat, Feb 23, 2008 at 5:13 AM, Ronald Schmidt > <ron...@so...> wrote: > >> I am looking to generate easy visualizations of >> objects serialized in a database USING the underlying model. >> > > It sounds like you're talking about a glue between "model" components > like dbix::class, class::dbi, etc? > Close. Yes a glue layer between HTML::Template and a database. I could try to use some of these higher layer abstractions (including Rose:DB) or use a modern DBI layer with its primay_key/primary_key_info/foreign_key_info functions ... > What would drive it? An existing template, or an existing data > definition? I see those two choices like this: > > 1) For a data structure, create a template on the fly, and populate it? > - Isn't that data dumper? > 1) Is NOT the driver. As I see it, it is often difficult to guess the structure of underlying objects correctly from a schema. > 2) For a template, get a list of params in the template and populate > them if the same-named item is found in a data structure (retrieved > from a model component)? > 2) Is the proposed driver. Retrieved from model component or schema. > Is that right? > It all sounds harder to explain than I thought it would be to use ;). Any further thoughts? > Mark > <html> <head><title>Test Template</title> <body> <TMPL_LOOP NAME="+books"> <ul> <li />Title is "<TMPL_VAR NAME=".title">" <li />ISBN is <TMPL_VAR NAME=".isbn"> <li />Authors are: <ul> <!-- name below is shorthand for +books.book_id.authors --> <!-- could still be abbreviated to +authors if fk's link tables --> <TMPL_LOOP NAME=".book_id.authors:ORDER_BY:.last_name,.first_name" > <li /><TMPL_VAR NAME=".last_name">, <TMPL_VAR NAME=".first_name"> </TMPL_LOOP> </ul> </ul> </TMPL_LOOP> </body> </html> |
From: Mark F. <azf...@gm...> - 2008-02-23 17:14:06
|
On Sat, Feb 23, 2008 at 5:13 AM, Ronald Schmidt <ron...@so...> wrote: > I am looking to generate easy visualizations of > objects serialized in a database USING the underlying model. It sounds like you're talking about a glue between "model" components like dbix::class, class::dbi, etc? What would drive it? An existing template, or an existing data definition? I see those two choices like this: 1) For a data structure, create a template on the fly, and populate it? - Isn't that data dumper? 2) For a template, get a list of params in the template and populate them if the same-named item is found in a data structure (retrieved from a model component)? Is that right? Mark |
From: Ronald S. <ron...@so...> - 2008-02-23 12:14:00
|
Sébastien Aperghis-Tramoni wrote: > Ronald Schmidt wrote: > If I understand correctly your question, you probably want to write a > producer module for SQL::Translator, the set of modules behind SQL Fairy. > » http://search.cpan.org/dist/SQL-Translator/ > » http://sqlfairy.sourceforge.net/ As far as I can tell from looking at SQL::Translator producers, the producers generate visualizations or alternate serializations of a database model whereas I am looking to generate easy visualizations of objects serialized in a database USING the underlying model. If you now review the sample html template included in my initial email, do you think that you understand the question? Do you know of a module providing the functionality or find the design to be of sufficient interest to for a new module? |
From: Sébastien Aperghis-T. <mad...@fr...> - 2008-02-23 00:40:39
|
Ronald Schmidt wrote: > Given the data model below, does anyone know of a package or module > that > would generate code for, or fill in, an HTML::Template like that > provided below the database ddl? If not, would there be interest in > such a module if I could create it? If I understand correctly your question, you probably want to write a producer module for SQL::Translator, the set of modules behind SQL Fairy. » http://search.cpan.org/dist/SQL-Translator/ » http://sqlfairy.sourceforge.net/ -- Sébastien Aperghis-Tramoni Close the world, txEn eht nepO. |
From: Ronald S. <ron...@so...> - 2008-02-22 12:41:10
|
Given the data model below, does anyone know of a package or module that would generate code for, or fill in, an HTML::Template like that provided below the database ddl? If not, would there be interest in such a module if I could create it? Ron create table books ( book_id integer, title varchar(1024), isbn varchar(80) ); create table authors ( author_id integer, book_id integer references books(book_id), last_name varchar(80), first_name varchar(80) ); <html> <head><title>Test Template</title> <body> <TMPL_LOOP NAME="+books"> <ul> <li />Title is "<TMPL_VAR NAME=".title">" <li />ISBN is <TMPL_VAR NAME=".isbn"> <li />Authors are: <ul> <!-- name below is shorthand for +books.book_id.authors --> <!-- could still be abbreviated to +authors if fk's link tables --> <TMPL_LOOP NAME=".book_id.authors:ORDER_BY:.last_name,.first_name" > <li /><TMPL_VAR NAME=".last_name">, <TMPL_VAR NAME=".first_name"> </TMPL_LOOP> </ul> </ul> </TMPL_LOOP> </body> </html> |
From: Jesse E. <je...@er...> - 2008-02-15 23:39:47
|
Krang v3.01 Release: February 15, 2008 Release Summary This release adds many new, and often requested features. Krang now supports multiple windows, permitting users to edit more than one story at a time. A syntax-highlighting text editor has been added for editing templates and text-based media (CSS, Javascript, HTML, XML, etc.). Numerous small bugs have been fixed, and performance enhanced. Significant improvements have been made to Krang's UTF-8 (Unicode) support. Major changes in this release include: * Multiple Krang window support. Edit more than one story at once! * Syntax highlighting for template editing. * Online editing of text media (e.g.: CSS, Javascript, HTML, text, XML, etc.) * Previewing a story now respects edited form fields -- no more endless "save & stay + preview" * When editing media, made "Save" and "Save & Stay" buttons automatically publish to preview. * Added ability to replace one story with another in one step. * Improved UTF-8 support. * Fixed numerous bugs and improved overall performance. About Krang Krang is an open source web publishing/content management system, particularly well suited for high volume magazine-style web sites. Originally developed in 2003 by Primedia, Krang is currently used by hundreds of well-known web sites including New York Magazine, Motor Trend, Soap Opera Digest, In-Fisherman, Guns & Ammo, Florida Sportsman, Game & Fish, Equisearch.com, Power & Motor Yacht, and many more. Krang provides a powerful and easy to use story and media editing environment for website editors, as well as a complete template development environment for web designers. On the back-end, Perl programmers can customize Krang to control the data entered in the story editor and add code to drive the templates to build output. Krang can be enhanced with add-ons containing new skins and other new features. Krang easily handles large data sets and can manage multiple websites in a single installation. Krang Links Krang CMS web site: http://www.krangcms.com Full change log: http://www.krangcms.com/docs/changelog.html#3_01__february_1__2008 Download from SourceForge: http://sourceforge.net/project/showfiles.php?group_id=103045 Mailing lists: http://lists.sourceforge.net/mailman/listinfo/krang-devel http://lists.sourceforge.net/mailman/listinfo/krang-general Bug Tracker: http://bugzilla.krangcms.com Jesse Erlbaum The Erlbaum Group, LLC 817 Broadway, 10th floor New York, NY 10003 http://erlbaum.net je...@er... |
From: Dawid J. <djs...@gm...> - 2008-01-12 17:34:00
|
Hi Raful, This is a mod_perl issue as you are not sending the HTTP headers = properly. You send the headers by calling the=20 $r->content_type( 'text/html'); In you code you have a call $r->content_type('text/plain');=20 This will cause the browser to interpret it for you as plain text. = Mod_perl sends its own headers when you set the content type so there is = no need for this: print "Content-Type: text/html\n\n"; Regards Dawid Joubert Lead Web Developer on STARS software for Ksystems www.klogin.co.uk ----- Original Message -----=20 From: Raful Mr Mitchell H=20 To: Html-Template-Users (E-mail)=20 Sent: Friday, January 11, 2008 9:36 PM Subject: [htmltmpl] using H::T from within mod_perl handler My HTML::Template output appears in the browser like so when in a = mod_perl sub handler subroutine. The other three modules work fine. = This also works fine as a CGI. Content-Type: text/html <?xml version=3D"1.0" encoding=3D"UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns=3D"http://www.w3.org/1999/xhtml" xml:lang=3D"en" = lang=3D"en"> <head> <title>Management App</title> <LINK rel=3D"stylesheet" href=3D"../css/yanmastyles.css" = type=3D"text/css"> <script type=3D"text/javascript" > function addLoadEvent(func) { var oldonload =3D window.onload; if (typeof window.onload !=3D 'function' ) { window.onload =3D func; } else { window.onload =3D function() { oldonload(); func(); } } } function highlightRows() { if( !document.getElementsByTagName ) return false; var rows =3D document.getElementsByTagName( "tr" ); for( var i=3D0; i<rows.length; i++ ) { rows[i].onmouseover =3D function() { this.style.backgroundColor =3D "#d3d3d3"; } rows[i].onmouseout =3D function() { this.style.backgroundColor =3D "#fff"; } } } addLoadEvent(highlightRows); </script> </head> <body> <div id=3D"top"> <div id=3D"banner"> <a href=3D"index.html"><img = src=3D"../images/yanma-banner.jpg" alt=3D"Yanma" width=3D"900" height=3D"172" border=3D"0" /></a> </div> <div id=3D"menubar"> <ul id=3D"navigation"> <li><a = href=3D"/perl/choosemodel.pl"><span>Query</span></a></li> <li><a = href=3D"http://yanmadev.usmc-mccs.org/administration/update.html"><span>U= pdate</span></a></li> <li><a href=3D"#"><span>Add</span></a></li> <li><a href=3D"choose_router.html"><span>NBAR = Stats</span></a></li> <li><a = href=3D"choosebase.pl"><span>Portmapper</span></a></li> <li><a = href=3D"http://yanmadev.usmc-mccs.org"><span>Home</span></a></li> </ul> </div> <div id=3D"border"></div> </div> <div id=3D"content"> <h2>albasw02</h2> <h3>Cisco Catalyst 3550 24 10/100 baseT ports + 2 Gig uplinks fixed = configuration Layer 2/3 Ethernet Switch</h3> <h3>Fri Jan 11 16:16:52 2008</h3> =20 <table > <thead> <th>Interface</th> <th>Mac Address</th> <th>IP Address</th> <th>Device</th> <th>Controller/Printer</th> </thead> <tbody>=20 =20 <tr> <td>Fa0/13</td> <td>001d0909cd0d</td> <td>10.129.20.38</td> <td>albxp02006.windows.usmc-mccs.org</td> <td></td> </tr> =20 <tr> <td>Fa0/13</td> <td>001d0909cd0d</td> <td>10.129.20.38</td> <td>albxp02006.windows.usmc-mccs.org</td> <td></td> </tr> =20 <tr> <td>Fa0/13</td> <td>001d0909cd0d</td> <td>10.129.20.38</td> <td>albxp02006.windows.usmc-mccs.org</td> <td></td> </tr> =20 </tbody> </table> All the info is there and is correct, just not rendered. All = other modules within the app work great, just not this one. Below is my = Perl module.#!/usr/bin/perl -wpackage Handlers::PortMapper;use = warnings;use strict;use HTML::Template;use DBI;use Socket qw(:DEFAULT = :crlf);use dec_hex;use snmpSession;use SNMP;use Net::NBName;use = Net::Ping;use Apache2::Request ();use Apache2::Const -compile=3D>'OK'; # = %seen_vlans --tracks those vlans which are seen as each ports vlan = membership is looked at # %device --all results for each device found on = a switch are placed here for dispatching to a web page# @answer;my = @switch_row; #--hold results of db query for switchmy @router_row; = #--hold results of db query for router whose arp cache you wantmy = %devices_ref;my %hash;my $time; # --gets time query beganmy = $chosen_switch; #--switch passed via http form datamy $chosen_router; = #--switch passed via http form datamy $switch_ip; #--result one for = initial querymy $switch_model; #--result two for initial querymy = $devices_ref;my $router_ip; # --result for query of router addressmy = $dbh; #--database handlemy $sql; #--database querymy @loop_data; #--hold = hashes for my template# $i =3D 0 --counters# $j =3D 0 --counterssub = handler {my $r =3D shift;my $req =3D Apache2::Request->new( $r = );$r->content_type('text/plain'); my %mac_data;my @mac_array; #hold = individual hex digits returned by ipNetToMediaPhysAddressmy @loop_data = =3D (); #array of anonymous hashes which is dispatched to web page for = displaymy $template =3D HTML::Template->new( filename =3D> = '/home/mitch/www-dev/mod_perl/templates/portmapper.tmpl',debug =3D> = 1,die_on_bad_params =3D> 0 );my $time =3D localtime();$chosen_switch =3D = $req->param('chosen_switch');$chosen_switch =3D~ = s/(\s.*)//g;$chosen_router =3D $req->param( 'chosen_router' );$dbh =3D = DBI->connect( 'dbi:ODBC:MRIServer2k', 'mriinventory', 'Wysiwyg@3044',{ = PrintError =3D> 1, RaiseError =3D> 0, AutoCommit =3D> 1 } );$sql =3D = "SELECT address, chassis_description FROM tblLiveCisco WHERE = name=3D'$chosen_switch'";@switch_row =3D $dbh->selectrow_array( $sql = );$switch_ip =3D $switch_row[0];$switch_model =3D = $switch_row[1];@router_row =3D $dbh->selectrow_array("SELECT address = FROM tblLiveCisco WHERE name=3D'$chosen_router'" );$router_ip =3D = $router_row[0];$devices_ref =3D getDevices( $router_ip, $switch_ip, = 'public');foreach $_ (@{$devices_ref}) {%hash =3D %$_;push @loop_data, = \%hash ;}$template->param(CHOSEN_SWITCH =3D> $chosen_switch = );$template->param(MODEL =3D> $switch_model );$template->param(TIME =3D> = $time );$template->param(LOOP_DATA =3D> \@loop_data );print = "Content-Type: text/html\n\n";print $template->output;return = Apache2::Const::OK;}sub getDevices {my $router =3D shift;my $switch =3D = shift;my $community =3D shift;my @mac_array =3D ();my %seen_vlans =3D = ();my %ifnames; #holds the ifIndex number and names of portsmy %trunk; = #holds all ports on a switch that are trunkingmy %arpCache;my @data;my = @vlans; #all vlans found using vmVlan objectmy $arp_mib =3D = 'ipNetToMediaPhysAddress';my ( $mac_address,$ip, $dns_name, $device_type = );my $arp_session =3D snmpSession::openSession( $router , $community, 1 = );my $vb_arp =3D new SNMP::Varbind( [$arp_mib] );for(my $var =3D = $arp_session->getnext( $vb_arp );( $vb_arp->tag eq $arp_mib ) and not ( = $arp_session->{ErrorNum} );$var =3D $arp_session->getnext( $vb_arp )) = {my $ip_addr =3D ( $vb_arp->tag . $vb_arp->iid );$ip_addr =3D~ = s/$arp_mib\d+\.//g;my @vars =3D split(/:/, $var );for( my $x =3D 0; $x < = scalar( @vars ); $x++ ) {if( length( $vars[$x] ) < 2 ){$vars[$x] =3D = "0"."$vars[$x]";}push( @mac_array, $vars[$x] );}my $arp_mac_address =3D = join( "", @mac_array );push( @{$arpCache{$arp_mac_address}}, $ip_addr = );@mac_array =3D ();}if( $arp_session->{ErrorNum} ){ print "Got = $arp_session->{ErrorStr} for $router\n"; }my $vlan_session =3D = snmpSession::openSession ( $switch, $community, 1 );my $vb_vlan =3D new = SNMP::VarList( ['vmVlan'], ['ifName'], ['vlanTrunkPortDynamicStatus'] = );my @answers1 =3D $vlan_session->bulkwalk(0, 100, $vb_vlan );if( = $vlan_session->{ErrorNum} ) {print "Got ", $vlan_session->{ErrorStr}, = "on", $vlan_session->{DestHost}, " during Bulkwalk\n";}my $vlan_answer = =3D $answers1[0];my $ifName_answer =3D $answers1[1];my $trunk_ports =3D = $answers1[2];for( my $i =3D 0; $i < scalar(@$vlan_answer); $i++ ){my = $vlan =3D $vlan_answer->[$i]->[ 2];if ( !exists ($seen_vlans{$vlan} ) ) = {push( @vlans, $vlan );$seen_vlans{$vlan} =3D 1;}}for( my $j =3D 0; $j < = scalar(@$ifName_answer); $j++ ){my $index =3D = $ifName_answer->[$j]->[1];my $interface_name =3D = $ifName_answer->[$j]->[2];push @{$ifnames{$index}}, $interface_name;}for = ( my $p =3D 0; $p < scalar( @$trunk_ports ); $p++ ) {my $port_index =3D = $trunk_ports->[$p]->[1];if( $trunk_ports->[$p]->[2] eq 'trunking' = ){$trunk{$port_index} =3D 1;}}my $vb_cam =3D new SNMP::VarList( = ['dot1dTpFdbPort'], ['dot1dBasePortIfIndex'] );foreach $_ ( @vlans ) = {$community =3D "public@"."$_";my $cam_session =3D = snmpSession::openSession ( $switch, $community, 1 );my @answers2 =3D = $cam_session->bulkwalk(0, 1000, $vb_cam );my $fdbPorts =3D = $answers2[0];my $portIndexes =3D $answers2[1];for ( my $q =3D 0; $q < = scalar( @$fdbPorts ); $q++ ) {for( my $r =3D 0; $r < scalar( = @$portIndexes ); $r++ ) {if( $fdbPorts->[$q]->[2] =3D=3D = $portIndexes->[$r]->[1] && !exists( $trunk{ $portIndexes->[$r]->[2] } ) = ){$mac_address =3D lc(dec_hex::dec_to_hex( $fdbPorts->[$q]->[1] ) );if( = exists($arpCache{$mac_address} ) ) {$ip =3D = $arpCache{$mac_address}->[0];$dns_name =3D getName( $ip );$device_type = =3D getDeviceType( $ip );}else { $ip =3D undef; }if( !defined( $ip ) = ){if( $mac_address =3D~ /000255/o ){$device_type =3D 'Register';}elsif( = $mac_address =3D~ /000ff8/o ){$device_type =3D 'PSC handheld';}elsif( = $mac_address =3D~ /00a0f8/g ){$device_type =3D 'Symbol RF = device';}elsif( $mac_address =3D~ /001795/g ){$device_type =3D 'Cisco = Systems AP';}}my %device =3D (); $device{PORT} =3D "@{$ifnames{ = $portIndexes->[$r]->[2]} }";$device{MAC} =3D $mac_address;$device{IP} = =3D $ip;$device{DEVICE} =3D $dns_name;$device{TYPE} =3D = $device_type;push( @data, \%device );}}}}return \@data;}sub getName {my = $ip_address =3D shift(@_);my( $nbQuery, $nbStatus, $DNS, = $packed_binary_address );$packed_binary_address =3D inet_aton( = $ip_address);$DNS =3D gethostbyaddr( $packed_binary_address, AF_INET = );if( !$DNS ) {$nbQuery =3D Net::NBName->new;$nbStatus =3D = $nbQuery->node_status( $ip_address );if( defined $nbStatus ){$DNS =3D = $nbStatus->{names}->[0]->{name};}if( !$DNS ) { $DNS =3D 'unknown' = }}return $DNS;}sub getDeviceType {my $address =3D shift( @_ );my ( = $type, $rtt, $tcp_print, $addr, $host);$tcp_print =3D = Net::Ping->new("syn");$tcp_print->{port_num} =3D = "9100";$tcp_print->service_check( 1 );$tcp_print->ping( $address );if( ( = $host, $rtt, $addr ) =3D $tcp_print->ack ){$type =3D = "Printer";}else{$tcp_print =3D = Net::Ping->new("syn");$tcp_print->{port_num} =3D = "4500";$tcp_print->service_check( 1 );$tcp_print->ping( $address );if( ( = $host, $rtt, $addr ) =3D $tcp_print->ack ){$type =3D = "Controller"}}return $type;}1;Thanks, MitchMitchell Raful MCSE CCNP=20 MCB Quantico=20 Personal and Family Readiness (MRI)=20 3044 Catlin Avenue=20 Quantico, VA 22134=20 Com: 703-784-5991=20 DSN: 278-5991=20 Cell: 804-363-0731=20 -------------------------------------------------------------------------= ----- = -------------------------------------------------------------------------= Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. = http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketpl= ace -------------------------------------------------------------------------= ----- _______________________________________________ Html-template-users mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/html-template-users |
From: Sam T. <sa...@tr...> - 2008-01-11 23:45:24
|
On 1/11/08, Raful Mr Mitchell H <RA...@us...> wrote: > > My HTML::Template output appears in the browser like so when in a > mod_perl sub handler subroutine. The other three modules work fine. This > also works fine as a CGI. > This sounds like a server configuration problem to me. To prove it's not HTML::Template, try replacing: print $template->output; With: print "<h1>Hello World!</h1>\n"; If you see that as HTML code, not rendered, then HTML::Template is not your problem. You might try posting your question to the mod_perl list. Be sure to include the relevant section of your Apache config. -sam |
From: Raful Mr M. H <RA...@us...> - 2008-01-11 21:37:38
|
My HTML::Template output appears in the browser like so when in a = mod_perl sub handler subroutine. The other three modules work fine. = This also works fine as a CGI. Content-Type: text/html <?xml version=3D"1.0" encoding=3D"UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns=3D"http://www.w3.org/1999/xhtml" xml:lang=3D"en" = lang=3D"en"> <head> <title>Management App</title> <LINK rel=3D"stylesheet" href=3D"../css/yanmastyles.css" = type=3D"text/css"> <script type=3D"text/javascript" > function addLoadEvent(func) { var oldonload =3D window.onload; if (typeof window.onload !=3D 'function' ) { window.onload =3D func; } else { window.onload =3D function() { oldonload(); func(); } } } function highlightRows() { if( !document.getElementsByTagName ) return false; var rows =3D document.getElementsByTagName( "tr" ); for( var i=3D0; i<rows.length; i++ ) { rows[i].onmouseover =3D function() { this.style.backgroundColor =3D "#d3d3d3"; } rows[i].onmouseout =3D function() { this.style.backgroundColor =3D "#fff"; } } } addLoadEvent(highlightRows); </script> </head> <body> <div id=3D"top"> <div id=3D"banner"> <a href=3D"index.html"><img = src=3D"../images/yanma-banner.jpg" alt=3D"Yanma" width=3D"900" height=3D"172" border=3D"0" /></a> </div> <div id=3D"menubar"> <ul id=3D"navigation"> <li><a = href=3D"/perl/choosemodel.pl"><span>Query</span></a></li> <li><a = href=3D"http://yanmadev.usmc-mccs.org/administration/update.html"><span>U= pdate</span></a></li> <li><a href=3D"#"><span>Add</span></a></li> <li><a href=3D"choose_router.html"><span>NBAR = Stats</span></a></li> <li><a = href=3D"choosebase.pl"><span>Portmapper</span></a></li> <li><a = href=3D"http://yanmadev.usmc-mccs.org"><span>Home</span></a></li> </ul> </div> <div id=3D"border"></div> </div> <div id=3D"content"> <h2>albasw02</h2> <h3>Cisco Catalyst 3550 24 10/100 baseT ports + 2 Gig uplinks fixed = configuration Layer 2/3 Ethernet Switch</h3> <h3>Fri Jan 11 16:16:52 2008</h3> =20 <table > <thead> <th>Interface</th> <th>Mac Address</th> <th>IP Address</th> <th>Device</th> <th>Controller/Printer</th> </thead> <tbody>=20 =20 <tr> <td>Fa0/13</td> <td>001d0909cd0d</td> <td>10.129.20.38</td> <td>albxp02006.windows.usmc-mccs.org</td> <td></td> </tr> =20 <tr> <td>Fa0/13</td> <td>001d0909cd0d</td> <td>10.129.20.38</td> <td>albxp02006.windows.usmc-mccs.org</td> <td></td> </tr> =20 <tr> <td>Fa0/13</td> <td>001d0909cd0d</td> <td>10.129.20.38</td> <td>albxp02006.windows.usmc-mccs.org</td> <td></td> </tr> =20 </tbody> </table> =20 All the info is there and is correct, just not rendered. All other = modules within the app work great, just not this one. Below is my Perl = module. #!/usr/bin/perl -w package Handlers::PortMapper; use warnings; use strict; use HTML::Template; use DBI; use Socket qw(:DEFAULT :crlf); use dec_hex; use snmpSession; use SNMP; use Net::NBName; use Net::Ping; use Apache2::Request (); use Apache2::Const -compile=3D>'OK'; =20 # %seen_vlans --tracks those vlans which are seen as each ports vlan = membership is looked at=20 # %device --all results for each device found on a switch are placed = here for dispatching to a web page # @answer; my @switch_row; #--hold results of db query for switch my @router_row; #--hold results of db query for router whose arp cache = you want my %devices_ref; my %hash; my $time; # --gets time query began my $chosen_switch; #--switch passed via http form data my $chosen_router; #--switch passed via http form data my $switch_ip; #--result one for initial query my $switch_model; #--result two for initial query my $devices_ref; my $router_ip; # --result for query of router address my $dbh; #--database handle my $sql; #--database query my @loop_data; #--hold hashes for my template # $i =3D 0 --counters # $j =3D 0 --counters sub handler { my $r =3D shift; my $req =3D Apache2::Request->new( $r ); $r->content_type('text/plain');=20 my %mac_data; my @mac_array; #hold individual hex digits returned by = ipNetToMediaPhysAddress my @loop_data =3D (); #array of anonymous hashes which is dispatched to = web page for display my $template =3D HTML::Template->new( filename =3D> = '/home/mitch/www-dev/mod_perl/templates/portmapper.tmpl', debug =3D> 1, die_on_bad_params =3D> 0 ); my $time =3D localtime(); $chosen_switch =3D $req->param('chosen_switch'); $chosen_switch =3D~ s/(\s.*)//g; $chosen_router =3D $req->param( 'chosen_router' ); $dbh =3D DBI->connect( 'dbi:ODBC:MRIServer2k', 'mriinventory', = 'Wysiwyg@3044', { PrintError =3D> 1, RaiseError =3D> 0, AutoCommit =3D> 1 } ); $sql =3D "SELECT address, chassis_description FROM tblLiveCisco WHERE = name=3D'$chosen_switch'"; @switch_row =3D $dbh->selectrow_array( $sql ); $switch_ip =3D $switch_row[0]; $switch_model =3D $switch_row[1]; @router_row =3D $dbh->selectrow_array("SELECT address FROM tblLiveCisco = WHERE name=3D'$chosen_router'" ); $router_ip =3D $router_row[0]; $devices_ref =3D getDevices( $router_ip, $switch_ip, 'public'); foreach $_ (@{$devices_ref}) { %hash =3D %$_; push @loop_data, \%hash ; } $template->param(CHOSEN_SWITCH =3D> $chosen_switch ); $template->param(MODEL =3D> $switch_model ); $template->param(TIME =3D> $time ); $template->param(LOOP_DATA =3D> \@loop_data ); print "Content-Type: text/html\n\n"; print $template->output; return Apache2::Const::OK; } sub getDevices { my $router =3D shift; my $switch =3D shift; my $community =3D shift; my @mac_array =3D (); my %seen_vlans =3D (); my %ifnames; #holds the ifIndex number and names of ports my %trunk; #holds all ports on a switch that are trunking my %arpCache; my @data; my @vlans; #all vlans found using vmVlan object my $arp_mib =3D 'ipNetToMediaPhysAddress'; my ( $mac_address,$ip, $dns_name, $device_type ); my $arp_session =3D snmpSession::openSession( $router , $community, 1 ); my $vb_arp =3D new SNMP::Varbind( [$arp_mib] ); for(my $var =3D $arp_session->getnext( $vb_arp ); ( $vb_arp->tag eq $arp_mib ) and not ( $arp_session->{ErrorNum} ); $var =3D $arp_session->getnext( $vb_arp ) ) { my $ip_addr =3D ( $vb_arp->tag . $vb_arp->iid ); $ip_addr =3D~ s/$arp_mib\d+\.//g; my @vars =3D split(/:/, $var ); for( my $x =3D 0; $x < scalar( @vars ); $x++ ) { if( length( $vars[$x] ) < 2 ) { $vars[$x] =3D "0"."$vars[$x]"; } push( @mac_array, $vars[$x] ); } my $arp_mac_address =3D join( "", @mac_array ); push( @{$arpCache{$arp_mac_address}}, $ip_addr ); @mac_array =3D (); } if( $arp_session->{ErrorNum} ){ print "Got $arp_session->{ErrorStr} for = $router\n"; } my $vlan_session =3D snmpSession::openSession ( $switch, $community, 1 = ); my $vb_vlan =3D new SNMP::VarList( ['vmVlan'], ['ifName'], = ['vlanTrunkPortDynamicStatus'] ); my @answers1 =3D $vlan_session->bulkwalk(0, 100, $vb_vlan ); if( $vlan_session->{ErrorNum} ) { print "Got ", $vlan_session->{ErrorStr}, "on", = $vlan_session->{DestHost}, " during Bulkwalk\n"; } my $vlan_answer =3D $answers1[0]; my $ifName_answer =3D $answers1[1]; my $trunk_ports =3D $answers1[2]; for( my $i =3D 0; $i < scalar(@$vlan_answer); $i++ ) { my $vlan =3D $vlan_answer->[$i]->[ 2]; if ( !exists ($seen_vlans{$vlan} ) ) { push( @vlans, $vlan ); $seen_vlans{$vlan} =3D 1; } } for( my $j =3D 0; $j < scalar(@$ifName_answer); $j++ ) { my $index =3D $ifName_answer->[$j]->[1]; my $interface_name =3D $ifName_answer->[$j]->[2]; push @{$ifnames{$index}}, $interface_name; } for ( my $p =3D 0; $p < scalar( @$trunk_ports ); $p++ ) { my $port_index =3D $trunk_ports->[$p]->[1]; if( $trunk_ports->[$p]->[2] eq 'trunking' ) { $trunk{$port_index} =3D 1; } } my $vb_cam =3D new SNMP::VarList( ['dot1dTpFdbPort'], = ['dot1dBasePortIfIndex'] ); foreach $_ ( @vlans ) { $community =3D "public@"."$_"; my $cam_session =3D snmpSession::openSession ( $switch, $community, 1 ); my @answers2 =3D $cam_session->bulkwalk(0, 1000, $vb_cam ); my $fdbPorts =3D $answers2[0]; my $portIndexes =3D $answers2[1]; for ( my $q =3D 0; $q < scalar( @$fdbPorts ); $q++ ) { for( my $r =3D 0; $r < scalar( @$portIndexes ); $r++ ) { if( $fdbPorts->[$q]->[2] =3D=3D $portIndexes->[$r]->[1] && !exists( = $trunk{ $portIndexes->[$r]->[2] } ) ) { $mac_address =3D lc(dec_hex::dec_to_hex( $fdbPorts->[$q]->[1] ) ); if( exists($arpCache{$mac_address} ) ) { $ip =3D $arpCache{$mac_address}->[0]; $dns_name =3D getName( $ip ); $device_type =3D getDeviceType( $ip ); } else { $ip =3D undef; } if( !defined( $ip ) ) { if( $mac_address =3D~ /000255/o ) { $device_type =3D 'Register'; } elsif( $mac_address =3D~ /000ff8/o ) { $device_type =3D 'PSC handheld'; } elsif( $mac_address =3D~ /00a0f8/g ) { $device_type =3D 'Symbol RF device'; } elsif( $mac_address =3D~ /001795/g ) { $device_type =3D 'Cisco Systems AP'; } } my %device =3D ();=20 $device{PORT} =3D "@{$ifnames{ $portIndexes->[$r]->[2]} }"; $device{MAC} =3D $mac_address; $device{IP} =3D $ip; $device{DEVICE} =3D $dns_name; $device{TYPE} =3D $device_type; push( @data, \%device ); } } } } return \@data; } sub getName { my $ip_address =3D shift(@_); my( $nbQuery, $nbStatus, $DNS, $packed_binary_address ); $packed_binary_address =3D inet_aton( $ip_address); $DNS =3D gethostbyaddr( $packed_binary_address, AF_INET ); if( !$DNS ) { $nbQuery =3D Net::NBName->new; $nbStatus =3D $nbQuery->node_status( $ip_address ); if( defined $nbStatus ) { $DNS =3D $nbStatus->{names}->[0]->{name}; } if( !$DNS ) { $DNS =3D 'unknown' } } return $DNS; } sub getDeviceType { my $address =3D shift( @_ ); my ( $type, $rtt, $tcp_print, $addr, $host); $tcp_print =3D Net::Ping->new("syn"); $tcp_print->{port_num} =3D "9100"; $tcp_print->service_check( 1 ); $tcp_print->ping( $address ); if( ( $host, $rtt, $addr ) =3D $tcp_print->ack ) { $type =3D "Printer"; } else{ $tcp_print =3D Net::Ping->new("syn"); $tcp_print->{port_num} =3D "4500"; $tcp_print->service_check( 1 ); $tcp_print->ping( $address ); if( ( $host, $rtt, $addr ) =3D $tcp_print->ack ) { $type =3D "Controller" } } return $type; } 1; Thanks, =20 Mitch Mitchell Raful MCSE CCNP=20 MCB Quantico=20 Personal and Family Readiness (MRI)=20 3044 Catlin Avenue=20 Quantico, VA 22134=20 Com: 703-784-5991=20 DSN: 278-5991=20 Cell: 804-363-0731=20 =20 |
From: Raful Mr M. H <RA...@us...> - 2008-01-09 13:20:12
|
Thanks! That should help alot. Since I also want the mac address I can = do something like... =20 @keys =3D keys %{$arpCache{$mac_address}}; foreach $key @keys { push @outer_loop, { mac_address =3D> $_ }; } in the template <TMPL_LOOP outer_loop> <TMPL_VAR mac_address> <TMPL_LOOP arp_cache_mac_address> <TMPL_VAR ip_address> </TMPL_LOOP arp_cache_mac_address> </TMPL_LOOP outer_loop> =20 Thanks again! =20 Mitchell Raful MCSE CCNP=20 MCB Quantico=20 Personal and Family Readiness (MRI)=20 3044 Catlin Avenue=20 Quantico, VA 22134=20 Com: 703-784-5991=20 DSN: 278-5991=20 Cell: 804-363-0731=20 -----Original Message----- From: Mathew Robertson [mailto:mat...@ne...] Sent: Tuesday, January 08, 2008 6:02 PM To: Raful Mr Mitchell H Cc: htm...@li... Subject: Re: [htmltmpl] hash of hashes Without further information on what you are trying to do and why you are = making the hash like so - I'm not sure what you are asking. ie: what are = you trying to loop through, a list of IP addresses? the arp cache? assuming the IP address: my $ht =3D HTML::Template->new("some.tmpl"); my @loop; foreach (@{$arpCache{$mac_address}}) { push @loop, { ip_address =3D> $_ }; } $ht->param(arp_cache_mac_address =3D> \@loop); in the "some.tmpl": <TMPL_LOOP arp_cache_mac_address> ... <TMPL_VAR ip_address> ... </TMPL_LOOP> Alternatively if you are willing to change the push(...), you could = write it as: push( @{$arpCache{$mac_address}}, { ip_address =3D> $ip_addr } ); ... $ht->param(arp_cache_mac_address =3D> $arpCache{$mac_address} ); Hope this helps, Mathew Raful Mr Mitchell H wrote:=20 My code puts together a hash like so... =20 push( @{$arpCache{$mac_address}}, $ip_addr ); =20 How on earth could I get that output via a TMPL_LOOP with TMPL_VAR? Or = is there a different way? =20 Thanks, =20 Mitch Mitchell Raful MCSE CCNP=20 MCB Quantico=20 Personal and Family Readiness (MRI)=20 3044 Catlin Avenue=20 Quantico, VA 22134=20 Com: 703-784-5991=20 DSN: 278-5991=20 Cell: 804-363-0731=20 =20 _____ =20 -------------------------------------------------------------------------= Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketpl= ace _____ =20 _______________________________________________ Html-template-users mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/html-template-users =20 |
From: Mathew R. <mat...@ne...> - 2008-01-08 23:02:04
|
Without further information on what you are trying to do and why you are making the hash like so - I'm not sure what you are asking. ie: what are you trying to loop through, a list of IP addresses? the arp cache? assuming the IP address: my $ht = HTML::Template->new("some.tmpl"); my @loop; foreach (@{$arpCache{$mac_address}}) { push @loop, { ip_address => $_ }; } $ht->param(arp_cache_mac_address => \@loop); in the "some.tmpl": <TMPL_LOOP arp_cache_mac_address> ... <TMPL_VAR ip_address> ... </TMPL_LOOP> Alternatively if you are willing to change the push(...), you could write it as: push( @{$arpCache{$mac_address}}, { ip_address => $ip_addr } ); ... $ht->param(arp_cache_mac_address => $arpCache{$mac_address} ); Hope this helps, Mathew Raful Mr Mitchell H wrote: > My code puts together a hash like so... > > push( @{$arpCache{$mac_address}}, $ip_addr ); > > How on earth could I get that output via a TMPL_LOOP with TMPL_VAR? > Or is there a different way? > > Thanks, > > Mitch > > Mitchell Raful MCSE CCNP > MCB Quantico > Personal and Family Readiness (MRI) > 3044 Catlin Avenue > Quantico, VA 22134 > Com: 703-784-5991 > DSN: 278-5991 > Cell: 804-363-0731 > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > ------------------------------------------------------------------------ > > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users > |
From: Raful Mr M. H <RA...@us...> - 2008-01-08 21:55:36
|
My code puts together a hash like so... =20 push( @{$arpCache{$mac_address}}, $ip_addr ); =20 How on earth could I get that output via a TMPL_LOOP with TMPL_VAR? Or = is there a different way? =20 Thanks, =20 Mitch Mitchell Raful MCSE CCNP=20 MCB Quantico=20 Personal and Family Readiness (MRI)=20 3044 Catlin Avenue=20 Quantico, VA 22134=20 Com: 703-784-5991=20 DSN: 278-5991=20 Cell: 804-363-0731=20 =20 |
From: Mark F. <azf...@gm...> - 2007-12-19 17:33:33
|
On 12/19/07, Brad Baxter <bm...@ma...> wrote: > And while it's easy for me to figure this out, I have a hard time believing > that it would be easy for H::T to know exactly what I want. But what if > there were a good mechanism for communicating that. Wait, that > describes filters ... I think you're on the right track. But, I would go further by saying that maybe this filter should be built-in and available via a switch on the new method. The default behavior seems to be unintuitive because it leads everyone to ask "what's with the extra ... ?" it might be valuable to make the standard "use a filter" response more standard to the package. It would be part of the documentation. Easy to correlate by newbies. Mark |
From: Brad B. <bm...@ma...> - 2007-12-19 16:25:36
|
On Dec 19, 2007 10:54 AM, Alex Teslik <al...@ac...> wrote: > On Wed, 19 Dec 2007 14:02:59 +0100, Rhesa Rozendaal wrote > > > > There's a conflict between indenting your template for readability, > > and the amount of whitespace that ends up in the output. > > > > Very well put! > > I beat this horse more deader a while back (and someone before me beat it > dead > too): > > > http://www.mail-archive.com/htm...@li.../msg01959.html > > It seems to me that the arguments in the conversation that links to are pretty well put, too. A simple filter added to the program does the trick: 1 #!/usr/local/bin/perl 2 3 use strict; 4 use warnings; 5 use HTML::Template; 6 7 my $html_template_filter = sub { 8 my $sref = shift; 9 for( $$sref ) { 10 s| <TMPL_LOOP (.*?)>\s* |<TMPL_LOOP $1>|gx; 11 s| </TMPL_LOOP>\s* |</TMPL_LOOP>|gx; 12 } 13 }; 14 15 my @array = <DATA>; 16 my $template = HTML::Template->new( arrayref => \@array, 17 filter => $html_template_filter ); 18 $template->param( loop => [ 19 {line => "line1"}, 20 {line => "line2"}, 21 {line => "line3"}, 22 ] ); 23 my $stuff = $template->output; 24 print $stuff; 25 26 __DATA__ 27 ########################################## 28 <TMPL_LOOP name="loop"> 29 <TMPL_VAR name="line"> 30 </TMPL_LOOP> 31 ########################################## Output: ########################################## line1 line2 line3 ########################################## (Assuming that's the trick I wanted.) It's relatively easy for me to figure out how to filter the template to produce the plain text I want. Maybe that's not so easy for a novice. Maybe a cookbook for this sort of thing could be helpful for novices and everyone else, too. And/or as someone mentioned, a library of common filters. And while it's easy for me to figure this out, I have a hard time believing that it would be easy for H::T to know exactly what I want. But what if there were a good mechanism for communicating that. Wait, that describes filters ... Regards, -- Brad |
From: Alex T. <al...@ac...> - 2007-12-19 15:55:14
|
On Wed, 19 Dec 2007 14:02:59 +0100, Rhesa Rozendaal wrote > > There's a conflict between indenting your template for readability, > and the amount of whitespace that ends up in the output. > Very well put! I beat this horse more deader a while back (and someone before me beat it dead too): http://www.mail-archive.com/htm...@li.../msg01959.html Thanks, Alex |
From: Rhesa R. <rh...@cp...> - 2007-12-19 13:03:12
|
Mark Fuller wrote: > On 12/16/07, Brad Baxter <bm...@ma...> wrote: >> A template novice might complain that HTML::Template is adding extra >> line breaks, but of course, they are right there in the template. > > I'm not a template novice and I still complain about the extra line > breaks. I think it's debatable whether "they are right there in the > template." If the lines the <tmpl_*> tags are on are not actually > (template) content, I don't see why the line ends of those lines > should be considered emitable (template) content. The fact that so > many novices find this unintuitive would indicate it's not the correct > behavior. I agree. For plaintext stuff, you have to jump through hoops sometimes to get it all nicely formatted. I have some hideously long <tmpl_loop><tmpl_if ..> lines just to avoid all those added newlines. There's a conflict between indenting your template for readability, and the amount of whitespace that ends up in the output. Take this simple snippet: --- >8 --- <tmpl_loop foo> <tmpl_if bar> * <tmpl_var baz> </tmpl_if> </tmpl_loop> --- >8 --- I'd really like this to generate: --- >8 --- * item 1 * item 2 * item 3 --- >8 --- Instead, we get --- >8 --- * item 1 * item 2 * item 3 --- >8 --- To get the desired output, you'd have to write your template like this: --- >8 --- <tmpl_loop foo><tmpl_if bar>* <tmpl_var baz> </tmpl_if></tmpl_loop> --- >8 --- This gets painful pretty quickly. > But, if it would burden H:T with cumbersome logic, I've always been in > favor of leaving it alone for the sake of simplicity (which I like > about H:T). While I'm not a TT user, I do like the [% var -%] syntax to suppress the trailing newlines. The main reason why I have never bothered looking into this, is that we use H::T primarily for HTML generation, where the extra whitespace has no significance (in fact, we run it through HTML::Tidy afterwards anyway). rhesa |