Answers.Body: <p>I looked in <code>CRM.config</code> to see if there was a helpful variable, but there isn't.  I think you need to add this variable via PHP.</p>
  
  <p>From the <a href="https://docs.civicrm.org/dev/en/latest/standards/javascript/#server-side-variables" rel="nofollow noreferrer">CiviCRM Javascript Reference</a> on Server-Side Variables:</p>
  
  <p>In PHP:</p>
  
  <pre><code>$config = CRM_Core_Config::singleton();
  CRM_Core_Resources::singleton()-&gt;addVars('myNamespace', array('extensionsUrl' =&gt; $config-&gt;extensionsURL));
  </code></pre>
  
  <p>In JS:</p>
  
  <pre><code>src = CRM.vars.myNamespace.extensionsUrl + "/images/myimg.png"
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-07T04:33:55.953Z
Answers.Text: I tried but not working.
Answers.UserDisplayName: deepak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-07T04:43:40.917Z
Answers.Text: @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`?
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-07T05:00:07.647Z
Answers.Text: http://localhost/copy/sites/default/files/civicrm/ext/images/myimg.png . Here extension name is missing.
Answers.UserDisplayName: deepak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-07T11:10:48.400Z
Answers.Text: so can't you just add the extension name ?
Answers.UserDisplayName: Aidan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-08T02:59:20.893Z
Answers.Text: '$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.
Answers.UserDisplayName: deepak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-06T14:56:32.623Z
Answers.LastActivityDate: 2019-03-06T14:56:32.623Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>I am trying to insert a new image using an extension and I am put that image into images directory (under the extension directory);</p>
  
  <pre><code>CRM.$(function($){
     cj("#civicrm-menu").prepend('&lt;li class="menumain"&gt;&lt;span class="menumain-label"&gt;&lt;img src=""&gt;&lt;/img&gt;&lt;/span&gt;&lt;/li&gt;');
  });
  </code></pre>
  
  <p><br></p>
  
  <blockquote>
    <p>I tried to put like this</p>
  </blockquote>
  
  <pre><code>src ="images/myimg.png"
  </code></pre>
  
  <p>But it is not working.</p>
  
  <p>How to give a src path of that image ?</p>
  
Tags: <extension>
Title: Adding Image using javascript
ThreadText: # Adding Image using javascript
  
  (Asked by: username_0 on 2019-03-06)
  
  I am trying to insert a new image using an extension and I am put that image into images directory (under the extension directory);
  
  ```
  CRM.$(function($){
     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 ?
  
  **Tags:** extension
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-03-06. Score: 0
  
  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](https://docs.civicrm.org/dev/en/latest/standards/javascript/#server-side-variables) on Server-Side Variables:
  
  In PHP:
  
  ```
  $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"
  
  ```
  
  > **Comments:**
  > **username_0**: I tried but not working.  
  > **username_1**: @username_0 Without knowing what's not working about it, it's very hard to suggest a solution.  Can you print the variable with `console.log`?  
  > **username_0**: http://localhost/copy/sites/default/files/civicrm/ext/images/myimg.png . Here extension name is missing.  
  > **username_2**: so can't you just add the extension name ?  
  > **username_0**: '$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.  
  
  ---
  
  