How to avoid repeated code usage in jekyll


I have following code which will repeat hundreds of times in a post.

<a download="image" href=""><img class="lazyload card-img" onerror="'none'" data-src="" /></a><br><br>

Only link
is changing. Can I avoid the repeatation and call the code each time?


By using Jekyll includes.


Thanks @mmistakes for reply. I am newbie, can you give the correct code. The changing link repeats 2 times in the code


Have a read through how to use variables with includes for more help.

You’ll want to do something like:

<!-- _includes/your-include.html -->
<a download="image" href="{{ include.url }}"><img class="lazyload card-img" onerror="'none'" data-src="{{ include.url }}" /></a><br><br>

And then you can call it into your page with:

{% include your-include.html url="" %}


Thank you very much @mmistakes. It worked. But it is more resource heavy so I can’t use it…