Srcset() for any image?

I try the following code but it doesn’t work

<?php $feature_home_img = $kirby->url('assets').'/images/home-1.jpg'; ?>
<img class="home-img" srcset="<?= $feature_home_img->srcset([300, 400, 600])  ?>"  />

The console shows " Error. Call to a member function srcset() on string"
Is there any workaround?

Thanks!

Should be

<?php $feature_home_img = new Asset($kirby->root('assets').'/images/home-1.jpg'); ?>

You can’t call an object method on a string, but have to create an Asset object first.

1 Like

I learn something today. Thanks @texnixe!

1 Like