I am trying to insert a new image using an extension and I am put that image into images directory (under the extension directory);

   cj("#civicrm-menu").prepend('<li class="menumain"><span class="menumain-label"><img src=""></img></span></li>');

I tried to put like this

src ="images/myimg.png"

But it is not working.

How to give a src path of that image ?


I looked in CRM.config to see if there was a helpful variable, but there isn't. I think you need to add this variable via PHP.

From the CiviCRM Javascript Reference on Server-Side Variables:


$config = CRM_Core_Config::singleton();
CRM_Core_Resources::singleton()->addVars('myNamespace', array('extensionsUrl' => $config->extensionsURL));

In JS:

src = CRM.vars.myNamespace.extensionsUrl + "/images/myimg.png"
  • I tried but not working.
    – deepak
    Mar 7 '19 at 4:33
  • @deepak Without knowing what's not working about it, it's very hard to suggest a solution. Can you print the variable with console.log? Mar 7 '19 at 4:43
  • localhost/copy/sites/default/files/civicrm/ext/images/myimg.png . Here extension name is missing.
    – deepak
    Mar 7 '19 at 5:00
  • so can't you just add the extension name ?
    – Aidan
    Mar 7 '19 at 11:10
  • '$imgPath = E::url('images\myimg.png');' I used this code for getting an image path and it is working but when I clicked on any contact of activity or group tab then it appends so many time. I put this code in preProcess() method.
    – deepak
    Mar 8 '19 at 2:59

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.