Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$this->headLink() includes duplicated script

Just like I did before, I used the following code for my new project.

<?=$this->headLink()->appendStylesheet('/Layouts/admin/css/button.css');?>
<?=$this->headLink()->appendStylesheet('/Layouts/admin/css/inputText.css');?>
<?=$this->headLink()->appendStylesheet('/Layouts/admin/css/fancyTable.class.css');?>

when I open the website and view source, there are duplicated css link tags.

<link href="/Layouts/admin/css/button.css" media="screen" rel="stylesheet" type="text/css" ><link href="/Layouts/admin/css/button.css" media="screen" rel="stylesheet" type="text/css" >
<link href="/Layouts/admin/css/inputText.css" media="screen" rel="stylesheet" type="text/css" ><link href="/Layouts/admin/css/button.css" media="screen" rel="stylesheet" type="text/css" >
<link href="/Layouts/admin/css/inputText.css" media="screen" rel="stylesheet" type="text/css" >
<link href="/Layouts/admin/css/fancyTable.class.css" media="screen" rel="stylesheet" type="text/css" >

<link href="/Layouts/admin/css/button.css" media="screen" rel="stylesheet" type="text/css" >
<link href="/Layouts/admin/css/inputText.css" media="screen" rel="stylesheet" type="text/css" >
<link href="/Layouts/admin/css/fancyTable.class.css" media="screen" rel="stylesheet" type="text/css" >
<link href="/Layouts/admin/css/divine.css" media="screen" rel="stylesheet" type="text/css" >

What is going on with my code??

like image 860
Moon Avatar asked Dec 08 '25 10:12

Moon


1 Answers

You shouldn't echo them all individually.

There should be one place where the HeadLink helper is printed, and all the other calls only add the stylesheet to that helper to be printed. E.g. the following rules anywhere in your view scripts:

<?php $this->headLink()->appendStylesheet('/Layouts/admin/css/button.css'); ?>
<?php $this->headLink()->appendStylesheet('/Layouts/admin/css/inputText.css'); ?>
<?php $this->headLink()->appendStylesheet('/Layouts/admin/css/fancyTable.class.css'); ?>

And then this in your <head>:

<?= $this->headLink() ?>

Or, if they all go in the same place anyway, you can chain them together

<?= $this->headLink()
    ->appendStylesheet('/Layouts/admin/css/button.css')
    ->appendStylesheet('/Layouts/admin/css/inputText.css')
    ->appendStylesheet('/Layouts/admin/css/fancyTable.class.css'); ?>

which will print the contents of the HeadLink helper with those 3 stylesheets attached.

Also see the HeadLink helper Zend documentation; the example in particular.

like image 127
mercator Avatar answered Dec 10 '25 00:12

mercator



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!