0

I have themed a page on my Drupal 7 website by mentioning the template file as page--node--.tpl.php The CSS and Images which are coming on this page are getting picked from the site itself and not from the static url i have configured in CDN. Other than this page my website is picking CSS JS & Images from CDN Any suggestions ?

Basic page--node--123.tpl.php

<?php
global $base_url;
$img_actl_path =  "$base_url/".drupal_get_path('theme','theme-name')."/images/v1/";
?>
<a href="#"><img src="<?php print $img_actl_path;?>image1.jpg" width="380" height="197" /></a>
  • I created a new template with just image in anchor tag ( code updated in question ). Even this is not picking image from CDN – mjs Jan 25 '14 at 8:37
3

The problem is that you are not using the Drupal API.

The CDN module needs to be able to alter the path from your Drupal site to your CDN. It does this by catching the URL via hook_file_url_alter(), and changing it.

The proper way to to make a URL in this case is with file_create_url(). Something like this should work

function MYTHEME_preprocess_page(&$variables) {
  $path = drupal_get_path('theme', 'MYTHEME');
  $variables['mysrc'] = file_create_url($path . '/images/v1/image1.jpg');
}

And then in your theme you would use

<a href="#"><img src="<?php print $mysrc; ?>" width="380" height="197" /></a>

However, as Mołot suggests, using a proper theme function to make a renderable image would probably be best.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.