How to create Inline CSS Style Blocks in cakephp 4.x

How to create Inline CSS Style Blocks same like script ?

$this->Html->scriptStart(['block' => true]);
echo "alert('I am in the JavaScript');";
$this->Html->scriptEnd();

You need to echo scriptStart and scriptEnd function calls

//to create script in head tag
echo $this->Html->scriptStart(['block' => true]);
echo "alert('I am in the Head JavaScript');";
echo $this->Html->scriptEnd();
//to create script inline
echo $this->Html->scriptStart();
echo "alert('I am in the Inline JavaScript');";
echo $this->Html->scriptEnd();

I want to know how to create in-line css , like we do for script.

$this->Html->scriptStart([‘block’ => true]); is for script , but what about CSS ?

As per my knowledge you cannot do same for CSS, and I believe it’s not required.
Always use css in external css files for speed performance.

If you want to write css for specific need in the page
use

<style type="text/css">
	//css code
</style>

There is indeed no cssStart/End() equivalent, for whatever reason, but you can always use view blocks directly if you wanted to achieve the same:

$this->append('css'); ?>
<style>
.foo {
    color: #fff;
}
</style>
<?php $this->end();
1 Like

Perfect. I was looking for this.