Hi:I know this is not modperl specific, but, I use TemplateToolkit2 to create pages on my site. My site contains a lot of photos and I want to add listings with thumbnail preview. But element attributes magically appears when generating the page. The page contains no java script or other stuff that can account for this:
In my handler I create a list reference with one entry preview per page like this:
my $item; $item->{path} = getPath($page->{page_id}); $item->{title} = $page->{title}; $item->{ctime} = dateStr($page->{ctime}); my $text = $page->{page}; if (my ($src) = $text =~ /<img.*?src="(.*?)">/io) { # Get image source $src =~ s/\/?photo/photo\/thumb/gio; $item->{img} = $src; } $text =~ s/<object.*?>.*?<\/object>//go; # Remove object-element $text =~ s/<h\d id="title">.*?<\/h\d>//gio; $text =~ s/<p>\n?<\/p>/\n/go; # Replace paragraph by newline $text =~ s/<.*?>//go; # Remove all elements $text = substr($text,0,256); # Get first 256 chars $text =~ s/\.[^\.]*?$/./go; # Chomp to last period $text =~ s/\r?\n\r?\n\r?/\n/go; # Remove double new-lines $item->{text} = $text;So, the item contains the title, extract of the content and possibly path to a thumbnail image.
In my template I have this: [% FOREACH item IN list %] <div class="item"> [% IF item.img %] <div class="thumb"> <a href="[% item.path %]" title="[% item.title %]"> <img src="[% item.img %]"/> </a> </div> [% END %] <p> <b><a href="[% item.path %]" title="[% item.title %]"> [% item.title %] </a></b> Posted: [% item.ctime %]<br/> [% item.text %] </p> </div> [% END %] Which produces this output: <div class="item"> <div class="thumb"> <a href="/photos/81_19/" title="Beach of Paris"><img src="photo/thumb/81_19.jpg" alt="Beach of Paris" title="Beach of Paris" class="photo/thumb"/>
</a> </div> <p> <b><a href="/photos/81_19/" title="Beach of Paris">Beach of Paris</a></b> Posted: 2007-01-07 00:42:25 UTC+01<br/> This august in Paris they ... </p> </div>So: where does the alt, title and class attributes in the image element come from??? I tried first to set these in the template, and discovered the dublicates when I tried to validate the result. Now, removing these attributes from the template and restarting Apache several times, I still get these extra "ghost" attributes.
If you like to see for yourself without my edits, the generated output is here: http://www.locolomo.org/photos/ and the full template is here: http://www.locolomo.org/pub/src/xcms/tt2/list.tt2
Thanks, Erik -- Ph: +34.666334818 web: http://www.locolomo.org
smime.p7s
Description: S/MIME Cryptographic Signature