Welcome Guest, Not a member yet? Register   Sign In
Parse Template
#1

[eluser]rpe[/eluser]
Hey... i have a question about parse template class
Can anyone help me if i write somecode like "{code}" .....tag {code} , it can call view like $this->load->view(nameofview).
I have been read documentation on code igniter but tag {code} just can replace with container
example

$data['hello']='hello world'
$data['code']='it s me'
$this->parse->parse('template',$data)

----------------------
<html>
<body>
{hello}
{code}
</body>
</html>

but i want to replace "{code}" that i can include some another view in the root view


Thank you
#2

[eluser]renownedmedia[/eluser]
Get the view file you want to place where {code} is by doing something like this:

$string = $this->load->view('myfile', '', true);

Then replace code with what you want it to be:

$string2 = str_replace('{code}', $data['code'], $string);

Then finally spit it out to the screen
#3

[eluser]davidbehler[/eluser]
If you have many variable that need to be replace, you might try this:
Code:
$string = $this->load->view(‘myfile’, ‘’, true);
foreach($data as $key => $value)
{
   $string = str_replace("{$key}", $value, $string);
}

echo $string;
#4

[eluser]Phil Sturgeon[/eluser]
Surely you could just do this:

Code:
$data['hello']='hello world';
$data['code']= $this->load->view('viewfile', $data, TRUE);
$this->parse->parse('template',$data);
#5

[eluser]dezafu[/eluser]
how if i want to parse class and view to that template
#6

[eluser]Phil Sturgeon[/eluser]
Code:
$data['hello']='hello world';
$data['code']= $this->parser->parse('viewfile', $data, TRUE);
$this->parse->parse('template',$data);

Come on dude, read the manual! :-)
#7

[eluser]dezafu[/eluser]
that just template...

see http://ellislab.com/forums/viewreply/620213/
#8

[eluser]Phil Sturgeon[/eluser]
[quote author="dezafu" date="1249565201"]that just template...

see http://ellislab.com/forums/viewreply/620213/[/quote]

The reply in that post is suggesting the exact same thing as me.
#9

[eluser]Phil Sturgeon[/eluser]
Do you mean you want to parse the 'viewfile' but not the main template? If so:

Code:
$data['hello']='hello world';
$data['code']= $this->parser->parse('viewfile', $data, TRUE);
$this->load->view('template',$data);

Want me to chew for you as well?! :-p
#10

[eluser]dezafu[/eluser]
No.. parse the view... but i want to parse the controller...
not only view but with controller...




Theme © iAndrew 2016 - Forum software by © MyBB