CodeIgniter Forums
Include PHP code in variable pass to template, is it possible? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Include PHP code in variable pass to template, is it possible? (/showthread.php?tid=17720)



Include PHP code in variable pass to template, is it possible? - El Forum - 04-13-2009

[eluser]RJ[/eluser]
Hello,

I've built a custom form that will display the fields based on a config file. Using CI's form validation I need to include
Code:
<?= $this->lang->line('.$key.') ?>
In a variable and have it be processed in the view. Presently CI is stripping the "<?". First is it possible, second any thoughts on a fix?
Code:
$templ[$key] = '    <div class="oneField">
<label for="'.$key.'" class="preField">&lt;?= $this->lang->line('.$key.') ?&gt;:</label>
&lt;input type="text" id="'.$key.'" value="" name="'.$key.'" class="required" &gt;
<span class="reqMark">'.$print.'</span></div><br />';
}



Include PHP code in variable pass to template, is it possible? - El Forum - 04-13-2009

[eluser]kgill[/eluser]
You aren't going to be able to pass code in a variable, but you shouldn't need to. Is there some reason I'm missing that is preventing you from sending the value that $this->lang->line produces instead of the code?

Code:
$templ[$key] = '    <div class="oneField">
<label for="'.$key.'" class="preField">'. $this->lang->line('.$key.') .':</label>
&lt;input type="text" id="'.$key.'" value="" name="'.$key.'" class="required" &gt;
<span class="reqMark">'.$print.'</span></div><br />';
}



Include PHP code in variable pass to template, is it possible? - El Forum - 04-13-2009

[eluser]RJ[/eluser]
Nope, you are absolutely correct. I was thinking to much! Smile

Thanks @kgill