Welcome Guest, Not a member yet? Register   Sign In
Template Parser: Dont display var name if blank
#6

[eluser]Kriesi[/eluser]
[quote author="Jondolar" date="1258075252"]I would have thought that if the array variable was set but blank it would remove it but I don't use the built-in parser. Can you just replace the "missing" variable with an HTML comment like <!-- --> so it won't show up in the rendered page? A better option might be to modify the temlate parser and make it work properly.[/quote]

Well actually thats the case, if you set the string to $data[$my_var] = ""; it wont display. the problem I have is that I dont know which variables to set to empty (its a site with multiple languages and some of the content only gets displayed for some of the languages)

the solution I came up with is to check which variables are within the template before parsing and setting everything to empty, then make a database query and merge the 2 arrays so that all empty values that now have a value get overriden:

Code:
$template = $this->load->view('index', '', true);
preg_match_all('/\{(\w+)\}/', $template, $matches);

if($matches[1])
{        
    foreach($matches[1] as $value)
    {    
        $blankdata[$value] = "";
    }
}

$data = //database query here;
$data = array_merge((array)$blankdata, (array)$data;

$this->parser->parse('index',$data);


Messages In This Thread
Template Parser: Dont display var name if blank - by El Forum - 11-12-2009, 09:40 AM
Template Parser: Dont display var name if blank - by El Forum - 11-12-2009, 10:26 AM
Template Parser: Dont display var name if blank - by El Forum - 11-12-2009, 10:58 AM
Template Parser: Dont display var name if blank - by El Forum - 11-12-2009, 01:20 PM
Template Parser: Dont display var name if blank - by El Forum - 11-12-2009, 11:25 PM
Template Parser: Dont display var name if blank - by El Forum - 11-13-2009, 03:32 AM
Template Parser: Dont display var name if blank - by El Forum - 11-20-2009, 08:47 PM



Theme © iAndrew 2016 - Forum software by © MyBB