Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can cgi's start_html() method have multiple -script attributes?

I think the question is pretty self explanitory, but I'm using perl to generate a webpage. Starts off using:

$cgi->start_html(-title=>'myPage',-style=>{-src=>'style.css'},  -script=>{-type=>'JAVASCRIPT', -src=>'custom.js'}, );

List item

But what if I want to have multiple scripts in the the header? Or Multiple CSS style sheets?

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="custom.js"></script>
<link rel="stylesheet" href="css/basic.css" type="text/css" />
<link rel="stylesheet" href="css/style.css" type="text/css" />
like image 715
Atey1 Avatar asked Aug 15 '11 21:08

Atey1


2 Answers

Use anonymous array:

$cgi->start_html(
  -title=>'myPage',
  -style=>[{-src=>'style.css'},{-src=>'basic.css'}],
  -script=>[{-type=>'JAVASCRIPT', -src=>'custom.js'},{-type=>'JAVASCRIPT', -src=>'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js'}],
);
like image 91
Alexandr Ciornii Avatar answered Sep 30 '22 01:09

Alexandr Ciornii


Of course. When you think more than one, think array. When you think passing arrays as arguments, think array ref.

use warnings;
use strict;
use CGI qw(:standard);

print start_html(-title => "myPage",
                 -style => [ {-src=>"style.css"},
                             {-src=>"basic.css"}, ],
                 -script => [ {-type=>"text/javascript",
                               -src=>"custom.js"},
                              {-type=>"text/javascript",
                               -src=>"ohai.js"}, ], );

__END__

…snip…
<title>myPage</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="basic.css" />
<script src="custom.js" type="text/javascript"></script>
<script src="ohai.js" type="text/javascript"></script>
…snip…
like image 28
Ashley Avatar answered Sep 30 '22 03:09

Ashley