Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Html() *feature enhancement req*

Started by Muut Archive 11 years ago · 6 replies · 232 views
11 years ago

Hey team! Could the html media filter add width/height attributes to the <img> 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.

11 years ago

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

11 years ago

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.

11 years ago

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

11 years ago

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.

11 years ago

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.

11 years ago

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

https://github.com/Sommerregen/variadic

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

PHP
<?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.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1330 9 years ago
Archive · by Muut Archive, 9 years ago
2 922 9 years ago
Archive · by Muut Archive, 9 years ago
2 4051 9 years ago
Archive · by Muut Archive, 9 years ago
1 2930 9 years ago
Archive · by Muut Archive, 9 years ago
3 1108 9 years ago