0

I've got a helper method which renders some html along with the required css and js links. I am simply concatenating all the html tags and returning the built string. The helper method is something like this:

function display_linkPreview($data = array())
{
    $return = "<link rel=\"stylesheet\" class=\"cssStatics\" type=\"text/css\" href=".base_url()."assets/css/stylesheet.css\" />
        <script type=\"text/javascript\" src=".base_url()."assets/js/linkPreview.js\" ></script>
        <div>blah blah<div></div></div>";
    return $return;
}

And this is the way I am going to render the outpt of display_linkPreview in one of the views:

echo display_linkPreview($body);

The problem is that all the output of display_linkPreview, including the <link> and <script> tags will be rendered in the middle of HTML page where I have called echo. How can I modify display_linkPreview to add css and js tags to the <head> of html?

B Faley
  • 17,120
  • 43
  • 133
  • 223
  • codeigniter has its own template engine, but you are allowed to use any other template engine you want. probably the smarty template engine (or some other template engine) will have what you are looking for. – Kinjal Dixit Jan 08 '13 at 17:58

2 Answers2

0

You could use template style viewing, for example, you have main.php

<html>
.
.
<?php echo $linkPreview ; ?>
</html>

<body>
.
.
<div id='main'><?php $this->load($main); ?></div>
</body>

And your controller could look like this:

.
.
$data['main'] = "myview";
$data['linkPreview'] = display_linkPreview();

$this->load->vars($data);
$this->load->view('template/main');
lucasf991
  • 31
  • 6
0

try this link_tag. this will help you to link the css and js. Something like this.

<html>
<head>
    <title></title>
    <?php echo link_tag('resources/style.css');?>
</head>
<body>
<?php 
?>
</body>
</html>

here resources is the folder that contains the css file stlye

NIMISHAN
  • 1,265
  • 4
  • 20
  • 29