Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Carabiner question -- Codeigniter library

When I use the carabiner library, my css and js files are appended to the top of the page. Is there a way i could specify where the files should be appended maybe try to send the files as an array to my view files?

thanks

like image 741
flopperJ Avatar asked Jun 04 '26 13:06

flopperJ


2 Answers

May differ slightly based on how you are rending your views, but with the conventional, lackluster way of doing it, here's an example:

Home controller:

public function index()
{
  $this->carabiner->css('default.css')
  $this->carabiner->js('custom.js');
  $data['assets'] = $this->carabiner->display_string('both');

  $this->load->view('templates/header', $data);
  $this->load->view('home/index', $data);
  $this->load->view('templates/footer');
}

Header view:

<html>
<head>
<title>Title of Page</title>
<?php echo $assets; ?>
</head>
...
like image 167
jonsuh Avatar answered Jun 06 '26 03:06

jonsuh


This was one of my major annoyances with Carabiner, unbuffered output. Every output function echos the return value instead of.. returning it.

Without hacking up the library (which I would personally do), here is an example of how to do what your'e asking:

ob_start();
$this->carabiner->display('css');
$css = ob_get_clean();

Now you have a variable with the js/css tag output you can send to your view file or template. Without the output buffering, this would print the tags to your output immediately. Note that if you want, another workaround is to make sure you don't call the output functions until you need them, like in the template itself.

If you wanted to fix this permanently, go through the Carabiner library and replace every instance of echo $some_return_value; to return $some_return_value; (last line of any output function). There are a lot, so this will take a little time.

As far as returning arrays, I'm not too sure - I never made it that far with Carabiner (didn't like it). Hopefully this helps all the same. Good Luck!

Read more on output buffering: http://php.net/manual/en/book.outcontrol.php

like image 31
Wesley Murch Avatar answered Jun 06 '26 02:06

Wesley Murch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!