Skip to content
Advertisement

Smarty cdn output filter for images

Output filter for smarty which replaces image URL inside smarty templates with your cdn url

e.g. an image like:

<img src="/images/image.gif"/>

<img src="http://cdn.yoursite.com/images/image.gif"/>

Advertisement

Answer

I think there’s like that

<?php  function smarty_outputfilter_cdn($tpl_source, &$smarty)  {      if($_SERVER["SERVER_PORT"] == 80) {          $tpl_source = preg_replace('/("|')((./|/)[A-z0-9_-/@.]+.(jpg|jpeg|gif|png))("|')/i', ""http://cdn.yoursite.com\2"", $tpl_source);      }            return $tpl_source;  }  ?>
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement