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

Convert simple PHP script in Grav Twig

Started by Ramez 7 years ago · 0 replies · 378 views
7 years ago

I'm trying to transfer my current website to Grav.
I'm using i0.wp.com to resize images, and I'd like continuing using it, instead of the builtin Grav method.

However, I'm having a hard time implementing it into Grav.

I've tried several things including preg_replace and also the plugin way but I'm not able to do it.

Do you have any suggestions, how I can convert my simple PHP in Twig and make it work?

PHP
// Image
function getImage($img, $alt) {
    echo '<img class="lazyload" src="https://i0.wp.com/example.com/app/img/thumbnail.png" data-src="https://i1.wp.com/example.com/app/img/'.$img.'" data-srcset="https://i1.wp.com/example.com/app/img/'.$img.'?w=550 500w, https://i0.wp.com/example.com/app/img/'.$img.'?w=750 700w, https://i1.wp.com/example.com/app/img/'.$img.'?w=900w 1024w" alt="'.$alt.'">';
}

Suggested topics

Topic Participants Replies Views Activity
Support · by Paul Hodges, 4 weeks ago
19 489 6 days ago
Support · by Lauw, 1 week ago
2 106 7 days ago
Support · by Anna, 3 weeks ago
4 428 1 week ago
Support · by gtx, 4 weeks ago
4 379 3 weeks ago
Support · by Anna, 1 month ago
9 487 4 weeks ago