0
votes
<img class="lazy" title="Windows 8" alt="Windows 8" src="http://b.a.org/sites/default/files/styles/thumbnail/public/category_pictures/Windows%20Media%20Player%20alt.png?itok=NXy-3w5_" href="lazy" data-original="http://b.a.org/sites/default/files/styles/thumbnail/public/category_pictures/Windows%20Media%20Player%20alt.png?itok=NXy-3w5_">

I would like to adjust the src so that it can display "/sites/all/themes/s5/images/blank.jpg" rather than the image url. Can you help me modify the below code I am using in Drupal 7's template.php to make this happen?

function s5_preprocess_image(&$variables) {
 if ($variables['style_name'] == 'thumbnail') {
     $variables['attributes']['class'][] = 'lazy';
     $variables['attributes']['data-original'][] = file_create_url($variables['path']);
}}

Thanks very much!!

1
total guess here, but try this: $variables['attributes']['data-original'][] = '/sites/all/themes/s5/images/blank.jpg'; or try this: $variables['attributes']['src'][] = '/sites/all/themes/s5/images/blank.jpg'; - prograhammer
I've tried the "['src']" bit and it still shows the same output. Nothing changes. - Bogen Dorpher
What happens if you change the $variables['path']? Add the line: $variables['path'] = '/sites/all/themes/s5/images/blank.jpg'; just above the "if" statement. - prograhammer
we're getting somewhere!! that changed both the src and data-original to the custom path. I want to keep data-original and just modify the src, for lazyloading purposes. - Bogen Dorpher
see answer...setting the path after the "if" block should do it - prograhammer

1 Answers

1
votes

Added a line to the bottom of the "if" block:

function s5_preprocess_image(&$variables) {
   if ($variables['style_name'] == 'thumbnail') {
       $variables['attributes']['class'][] = 'lazy';
       $variables['attributes']['data-original'][] = file_create_url($variables['path']);
       $variables['path'] = '/sites/all/themes/s5/images/blank.jpg';
   }
}