Parser non-set variables question/improvement - 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: Parser non-set variables question/improvement (/showthread.php?tid=34833) |
Parser non-set variables question/improvement - El Forum - 10-11-2010 [eluser]Deyan Yankov[/eluser] Hello. I am working generally with the parser class instead view. The problem is when some variable is not set. For example in the view file you place {variable} And if you do not set $data['variable'] = '', when viewing the file, the {variable} text appears. Is there a way to do so the non-set variables will be by default empty strings and do not show to the user? I tried something with preg_replace, but the problem is that the {} delimiters are used also for the $.post and it replaces anything between {} also in the javascript. Regards, Deyan Parser non-set variables question/improvement - El Forum - 10-11-2010 [eluser]Deyan Yankov[/eluser] This is the function I added to the parser library: function _parse_nonset($string){ $regex = "#([$this->l_delim])(.*)([$this->r_delim])#e"; return preg_replace($regex,"('')",$string); } Parser non-set variables question/improvement - El Forum - 10-11-2010 [eluser]victorche[/eluser] parser library has lots of stuff to be added/fixed if you ask me... I was searching for a solution like this also. But anyway, the approach is not good. I mean touching the system files. I think it is better if you extend the parser library and then post it here, if possible :] Parser non-set variables question/improvement - El Forum - 10-11-2010 [eluser]Deyan Yankov[/eluser] Yep, but the problem will stay also when you extend it. The javascript also uses {} delimiters and this function will replace anything between them. There must be some way to do the separation, or may be using other delimiters?? Parser non-set variables question/improvement - El Forum - 10-12-2010 [eluser]InsiteFX[/eluser] Read the users guide you can change the delimiters! And you should be extending the library not adding to it! InsiteFX Parser non-set variables question/improvement - El Forum - 10-12-2010 [eluser]Deyan Yankov[/eluser] Thanks! |