HtmlHelper vs plain HTML?

Hii there,

Today I was looking at the HtmlHelper for CakePHP 3.x but I was wondering:
Does using the HtmlHelper have any benefits over just using the plain HTML?

Eg. I’m mostly using the HTML helper in my head to load scripts like so:

<?= $this->Html->script([
]); ?>

But would this increase, decrease or do nothing for the performance of the site? (especially when the site gets high-traffic)
To me it seems like it would decrease the performance drastically as now it has to use cycles in PHP to loop over all the objects in the array and do some other stuff in PHP instead of just slamming it into there.

While there may be some decrease in performance from using this code instead of hard-coded HTML, I highly doubt it would be drastic. The helper can do things like locate assets in plugin folders and generate the correct links for them, and probably does a more reliable job of generating valid HTML overall. I use a combination of the two, mostly using the helper in places where information is already logically managed as an array, and inline HTML largely for containers of content that will be generated with code right there.

So, for example, if I’m outputting a div whose content was pre-assembled, I’ll generally prefer $this->Html->tag('div', $content) over <div><?= $content ?></div>, but if the content is going to be generated “here”, then I’ll use raw <div> and </div> around that code.


I see :slight_smile:
thanks, I’ll keep it in mind :slight_smile: