Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Search and replace in tpl
ela
Hi,
I'm almost embarrassed to have to ask this, but somehow I can't get it to work.
If the user has added a table in the DCR, but forgotten to set cellpadding, cellspacing and border, these settings should be added when generating the html file with the pt. The default should then be ="0", e.g. cellpadding="0".
There might be more than one table in the DCR, so each of them must be checked. Of course, if the attributes are already set by the user, they shouldn't be replaced.
I would be very happy for some help!
Regards,
Ela
Find more posts tagged with
Comments
Migrateduser
If you are only going to parse the DCR with TPL, then you can fix the tables in the TPL. This is the easy way, just replace iw_value calls with perl calls to iwpt_dcr_value and do substitutions on the variable before outputing it with iw_value or iwpt_output. But if other systems may parse the DCR you should fix the HTML (probably with FormAPI) before it is saved to the DCR. I have libraries that do this and can send you an example if needed.
CONTOLCENTERERROR.PNG
stingray
This should give you a start (note that if you have spaces around the "="s in your table attributes, this will break:
$data =~ s/(<(table) ([^>]+)>)/tableMunger($1,$2,$3)/eig;
sub tableMunger
{
my $line = shift;
my $tagstart = shift;
my $attrs = shift;
my
@attrs
= split(/\s+/, $attrs);
my %attr;
foreach my $a (
@attrs)
{
my ($a,$v) = split(/=/, $a);
$v =~ s/^['"]//;
$v =~ s/['"]$//;
$attr{lc($a)} = $v;
}
$attr{border} |= 0;
$attr{cellpadding} |= 0;
$attr{cellspacing} |= 0;
my $repl = join(" ", map {sprintf("%s=\"%s\"", $_, $attr{$_})} keys %attr);
$line =~ s/<$tagstart $attrs>/<$tagstart $repl>/i;
return $line;
}
Debit.txt
ela
Thanks a lot to both of you for your replies!
As all the DCRs use PTs to generate html, I used Stringrays code and it worked immediately - fantastic!!!
I put the code into a flatfile I use for other purposes as well, so that I don't have to repeat it in every tpl.
Thanks,
Ela