Why should I use Static Content Helpers?

Why should I use this?

<?php echo $this->tag->image("img/main.png"); ?>
<?php echo $this->tag->javascriptInclude("js/main.js"); ?>
<?php echo $this->tag->stylesheetLink("css/main.css"); ?>

Rather than use pure html tag?

<img src="img/main.png">
<script src="js/main.js"></script>
<link rel="stylesheet" href="css/main.css">

The tag helper is obviously more character than html tag, what is the benefit if I use tag helper?

I think you will benefit from the helper if you have to change the static path.



4.0k

Could you provide some example?

if I change folder js to javascript, I need change the path in both case

<?php echo $this->tag->javascriptInclude("javascript/main.js"); ?>
<script src="javascript/main.js"></script>

if I change the folder name of the app, since "js/main.js" is relative path, I don't need change anything in both case.`



21.7k
edited Jul '14

I think for simple projects with one or two js and css files it's overkill and a simple static call in header(template) is all you need.

one advantage, if you have more js and css file is to use collections and then you can expand them in controllers if neeeded and also minified them and save loading time/bandwith etc.

But for a simple project with 1-2 js and css files it's probably overkill.

what about if some projects need move statics to another website or cnd? the helper will reduce coding, i think