4
I know we can use Views.html file in Codeigniter, now I wonder if we can use tags {variavel}
directly as in Smarty.
Example:
<body>
<h1>{msg}</h1>
</body>
Are there any native replacement functions? Or do you have to use one more docked framework?
I would like to completely separate PHP from HTML, today I already do it with a class of my own, but I wonder if Codeigniter already does this.
As an example in substitution:
$data = array();
$CI = & get_instance();
$page = $CI->load->view('login.html', $data, true);
echo str_replace("{teste}", "Hello World", $page);
Codeigniter does not come with any template engine. Change
<?php echo $msg; ?>
for{$msg}
natively is not possible!– rray
I work with the IC, but as far as I know, it is necessary to adapt so that it recognizes these variables. I have never tried to use, always use $var->field;
– Sr. André Baill
Only the example title see the lines: $data = array(); $CI = & get_instance(); $page = $CI->load->view('login.html', $data, true); echo str_replace("{test}", "Hello World", $page);
– Marcelo
Edit the question and add this information. You haven’t commented on anything before replacements. I don’t think anything practical about these
str_replace()
...– rray
In fact str_replace is only for demonstration purposes, it should have a more user-friendly medium
– Marcelo
I’m sorry guys it’s my first post on the stack I’ll get the editor’s way to format better.
– Marcelo
You can edit the question code with the button
{ }
or identifying each line of code with 4 spaces :)– rray
Here are some editing guidelines
– Bacco
@rray think it’s the parser, as it was answered, huh
– Wallace Maxters