CodeIgniter Forums
No base_url() in view parser - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: No base_url() in view parser (/showthread.php?tid=74678)



No base_url() in view parser - futureisnow - 10-23-2019

Hi,
I read the site https://codeigniter4.github.io/CodeIgniter4/outgoing/view_parser.html , but it seems there is no non-php alternative for base_url(), which makes problems for loading css, pictures and other resources. Anyone knows how to use it?


RE: No base_url() in view parser - php_rocs - 10-24-2019

@futureisnow,

You could create a simple javascript library that has a base_url global variable.


RE: No base_url() in view parser - PaulD - 10-24-2019

Yeah, the parser class will not execute PHP.

Could you store the base_url as a variable so you do {base_url}{link} type thing?

Hope that makes sense.

Paul


RE: No base_url() in view parser - InsiteFX - 10-24-2019

You could store the base_url in a plugin there is a doc on it in the parser documentation.

All you would need to do is create a plugin for it.

There is already a plugin for site_url so you could copy that one.


RE: No base_url() in view parser - Codinglander - 04-21-2020

Here is my solution for this problem:

inside the controller:
PHP Code:
$this->data['bootstrap_css'] = base_url('assets/templates/kigh_bootstrap/css/bootstrap.min.css'); 

inside the view to parse:
Code:
<!-- Bootstrap core CSS -->
<link href="{bootstrap_css}" rel="stylesheet">

Also I did it with JS !

Enjoy Wink