0

Let's say I have a controller function with these lines:

$this->load->view('stdHeader_view');
echo "<div class='main'>";
$this->loadView('foo_view');
echo '</div>';
$this->load->view('stdFooter_view');

This won't do what I want, because $this->load->view() doesn't immediately echo the view it loads, so the 2 echoed lines will appear at the top of the file that ultimately gets generated:

<div class='main'></div><html>...

So is there a way to do what I want, essentially "echo" snippets of HTML inline within the controller and have them appear in the same place relative to the views loaded above and below them? Obviously I could accomplish this by making entire view files for <div class='main'> and </div>, but this seems a little silly.

1 Answer 1

1

Why would you wan't to do that? You should load your variable data into the view and manipulate the view from the data instead.

If this really has to be done, do something like this:

$html = $this->load->view('stdHeader_view', TRUE); //add TRUE to the second parameter, to return the views content
$html .= '<div class="main">';
$html .= $this->load->view('foo_view', TRUE);
$html .= '</div>';
$html .= $this->load->view('stdFooter_view', TRUE);
$this->output->set_output($html); //ends the controller and shows $html as output
Sign up to request clarification or add additional context in comments.

1 Comment

I think it's a completely reasonable thing to want to do :) Anyway, your last line indirectly led me to the answer, which is to use $this->output->append_output() in place of echo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.