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

1

10

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') 
Antrim answered 19/12, 2013 at 8:45 Comment(0)
D
10

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.

Damalas answered 19/12, 2013 at 9:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.