user_1234
user_1234

Reputation: 761

How to describe an image file path which is inside javascript file through codeigniter

For code requirement and security purpose I am calling image using its path inside main.js file, but for normal php (without framework) it works in this way but problem is that I am using Codeigniter and in codeigniter you can call using base_url() in php file but here image is inside js file so my question is how to specify image path inside js with codeigniter.

var modifytop={

controlHTML: '<img src="assets/img/arrow.png" style="width:40px; height:40px" />',
anchorkeyword: '#top',

 }

Upvotes: 1

Views: 287

Answers (1)

BEingprabhU
BEingprabhU

Reputation: 1686

Since JS cannot identify the PHP, PHP code will not execute.

So declare the base_url() in your HTML file.

<html>
<body>
<script type="text/javascript">
var base_url = "<?php echo base_url(); ?>";
</script>
//your rest of js source links
</body>
</html>

Then use the base_url variable in the JS file.

var modifytop={

controlHTML: '<img src="'+base_url+'"assets/img/arrow.png" style="width:40px; height:40px" />',
anchorkeyword: '#top',

 }

Set the base_url in config file as below

$config['base_url'] = "http://localhost/your-project-name/";

Upvotes: 1

Related Questions