Can Someone please Explain this two line used in CakePHP layout.ctp file. It seems both line used for adding css .Then what is the difference ? How they works.
$this->Html->css('cake.generic')
$this->fetch('css')
See the documentation on using blocks for script and CSS files.
In your view(s) you can use:
$this->Html->css('cake.generic')
In your layout(s), you can use:
$this->fetch('css')
A layout contains presentation code that wraps around a view. Anything you want to see in all of your views should be placed in a layout.
What this means is that when defining your layout, using $this->fetch('css')
will add in any css
blocks used in your views, so if in your views you'd put both:
$this->Html->css('cake.generic')
$this->Html->css('cake.special')
Using $this->fetch('css')
in your layout would include both. Note that without defining the block content first, it will not call anything. The addition of $this->Html->css('cake.generic')
in the layout file before the block call ensures it is added if it is not already included in a defined view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With