Html() *feature enhancement req*

Hey team! Could the html media filter add width/height attributes to the element?

They allow browsers to allocate the correct area for the image, and avoid page reflows after CSS/etc is downloaded. One of my pet hates is long image-heavy pages that repeatedly jump while you’re reading them.

(also, would GitHub be a better place to post this?)

It’s not as simple as it sounds. The biggest issue is knowing when to do this and when not. Certainly it could not be a global setting because more often than not, images are used in responsive layouts where image widths are not forced, but dynamically adjust to the space available.

There are other philosophical questions about whether or not you should even use these inline width/height tags at all even if the image size is fixed and never changes.

Do named parameters exist? I think I’d prefer write html(alt=“whatever”) anyway, I’ve already forgotten the positional ones.

PHP does not provide support for named arguments at this time. There is/was a proposal to add this functionality, but it was pretty much 50/50 voting last time I checked.

That said, it appears Twig does support passing in via named parameters, so maybe they are doing some matching with variable names. This needs to be tested and performance implications examined.

As rhukster said, Twig supports named arguments. For me it seems to be support it “automagically” without any modifications to custom filters and extensions (correct me if I’m wrong). For a usage example, see here http://de.slideshare.net/javier.eguiluz/twig-tips-and-tricks at slide 28.

Concerning PHP, although it doesn’t provide support for named arguments, you can write your own program implementing at least partially the behavior. I did this in my Variadic program

i.e. when using (note the associative array 'transform' => "strtoupper")

<?php
function concatenate($transform, $args) {
  ...
}

echo call_user_variadic_array('concatenate', array("I'd ",
    "like ", 4 + 2, " apples", 'transform' => "strtoupper"));
// result: "I'D LIKE 6 APPLES"
?>

You can have a look into this. It basically make use of the Reflection class, thus it could have performance implications.