Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP : Difference between " $this->fetch('css') & $this->Html->css('cake.generic') in cake php

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') 
like image 977
Asfaq Tamim Avatar asked Dec 19 '13 08:12

Asfaq Tamim


1 Answers

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.

like image 188
SW4 Avatar answered Nov 08 '22 00:11

SW4