Part of the EllisLab Network
   
 
Templates
Posted: 28 January 2007 10:04 AM   [ Ignore ]  
Summer Student
Total Posts:  8
Joined  01-28-2007

Hello,

I know that I can output a template with this code

$this->load->view("header");

but I want to use this function only for the final output, all other code shall be stored in variables e.g. in loops

$count = "0";
$output_bit = "";
while(
$count < 10){
  $count
++;
  
$output_bit .= $this->load->view("my_template_bit");
}

in my_template_bit is some html-code and php-variables
is there any way to use such kind of option so that i do not have to write the html-code inside the loop ?

$output_bit shall be available inside my outputpage

$this->load->view(“my_outputpage”);

Sorry for my terrible english wink

Profile
 
 
Posted: 28 January 2007 10:40 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  486
Joined  09-14-2006

Passing TRUE to the third parameter will cause view() to return.

$output_bit .= $this->load->view("my_template_bit", $data, TRUE);


Note: Use the second parameter to pass an array of variables to your view.

 Signature 

Code Igniter 1.5.4 / CentOS 5 / PHP 5.2.3 / Apache 2.2.2 / MySQL 5.0.27

Profile
 
 
Posted: 28 January 2007 11:03 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  314
Joined  12-26-2006

Hi Tester,

Try this:

File: the_controller.php

...
...
...
function
what_ever() {
   
  $data[
'the_heading'] = 'This is my header';
   
   
$count      = 0;
   
$output_bit = "";
   while(
$count < 10){
      $count
++;
      
$output_bit .= '<br />This value is from the_controller.php -->  ' .$count ;
   
}

   $data[
'string_from_controller'] = $output_bit;

   
$tmp_string = $this->load->view("my_template_bit", $data, TRUE); // check the help documention
   
ECHO $tmp_string ;

} // end function what_ever()

File: my_template_bit.php

<html>
<
head>
   <
title><?=$the_heading?></title>
</
head>
<
body>

   <
h1><?=$the_heading?></h1>
   
   
<?=$string_from_controller?>
   
</body>
</
html>

If the <?=$the_heading ?>  does not work then try <?php ECHO $the_heading ?>

Cheers,

John_Betong

PS If English is not your first language then it is very good.

Hello,

I know that I can output a template with this code

$this->load->view(“header”);

but I want to use this function only for the final output, all other code shall be stored in variables e.g. in loops
in my_template_bit is some html-code and php-variables
is there any way to use such kind of option so that i do not have to write the html-code inside the loop ?

$output_bit shall be available inside my outputpage

$this->load->view(“my_outputpage”);

Sorry for my terrible english

 Signature 

Real life ...  (development site)
My Hippy Trail    Source code   
Latest Project

Profile
 
 
Posted: 28 January 2007 12:13 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  8
Joined  01-28-2007

@ joeles

ok this works, but it isnt the right because I have to pass all varaibles via die data-array and this makes a lot of work, want only a simple method to eval html / php code

OK i will create my own parser

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 64453 Total Logged-in Users: 17
Total Topics: 80960 Total Anonymous Users: 1
Total Replies: 435690 Total Guests: 176
Total Posts: 516650    
Members ( View Memberlist )