Welcome Guest, Not a member yet? Register   Sign In
Parser non-set variables question/improvement
#1

[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
#2

[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);
}
#3

[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 :]
#4

[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??
#5

[eluser]InsiteFX[/eluser]
Read the users guide you can change the delimiters!

And you should be extending the library not adding to it!

InsiteFX
#6

[eluser]Deyan Yankov[/eluser]
Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB