Is there any method available in HTML::Template to do this?
This again? ;) No, you need to read and manipulate the DOM to do what you want. HTML::Template only works with it's specific tags/markers. Store $template->output()
into a variable. Read the variable with a parser such as Mojo::DOM to find the instances of forms and append your content. This example illustrates a solution:
#!/usr/bin/perl
use strict;
use warnings;
use Mojo::DOM;
# fake output of $template->output;
my $html = << 'HTML';
<html>
<head>
<title>test</title>
</head>
<body>
<form method="post">
<input type="text" id="name">
</form>
</body>
</html>
HTML
# you say you want to parse this from CGI
my $value ='foo';
# what you want to add
my $addme = "<input type='hidden' value='$value'>";
my $dom = Mojo::DOM->new();
$dom->parse( $html )->at('form')->child_nodes->first->append( $addme )->root;
print $dom;
prints:
<html>
<head>
<title>test</title>
</head>
<body>
<form method="post">
<input type="hidden" value="foo"><input id="name" type="text">
</form>
</body>
</html>
Edit.
Since we don't know what you're doing within your templates the sanest method is to base any changes on the output of your existing code. Meaning that you can safely add the method illustrated to the above before the point were you currently print the output of your template. You could use the code given as a one off update to actually write the change back to your templates, and the value rather than foo
could be an HTML::Template param.