Welcome Guest, Not a member yet? Register   Sign In
First Time Template Parser. Need an help.
#1

[eluser]daweb[/eluser]
Hi everybody,

it's first time I try to use the CI template parser class. It seems it works fine for me, but... I have a question, hope a studip question:

I have this array:
Code:
Array ( [path] => www.example.com  
[contentTitle] => Title
[ref] => 123
[city] => Rome
[rif] => 123
[details] => Array ( [0] =>
Array ( [dets_title] => First Block
[rows_details] => Array ( [0] =>
Array ( [dets_description] => First Description
[dets_value] => 1th Value ) [1] =>
Array ( [dets_description] => Second Description
[dets_value] => 2th Value ) ) ) [1] =>
Array ( [dets_title] => Second Block
[rows_details] => Array ( [0] =>
Array ( [dets_description] => First Description
[dets_value] => 1th Value) [1] =>
Array ( [dets_description] => Second Description
[dets_value] => 2th Value) [2] =>
Array ( [dets_description] => Third Description
[dets_value] => 3th Value) ) ) )
[content] => Main Content Entry [date] => 2009/01/31)

And in my view:
Code:
{entry_details}
<strong>{dets_title}</strong>
<ul class="tecnics-data line">
{rows_details}
<li{list_class}>
<span class="title_detail">{dets_description}</span>
<span{class_accepted}{title_accepted}>{dets_value}</span>
<br class="clearer" />
</li>
{/rows_details}
</ul>
<br class="clearer" />
{/entry_details}

It's works fine when I have a result, but when the array is empty I would want to do not print anything.
But it prints {entry_details}...

What's the best way?

Thank you!
#2

[eluser]roj[/eluser]
It's writing out the value name as it hasn't found any reference of it. One way to overcome this would be to declare all the items in the array as (even as a NULL value) somewhere very early on in the code: possibly in the Controller __construct if it's specific to one controller or else using hooks if it's across the whole system.
#3

[eluser]daweb[/eluser]
I'd try to set a "default value" to NULL, but it always return the {caption value}

Maybe I missed something...
#4

[eluser]roj[/eluser]
I've not actually tried this but try using simple empty values?
Code:
Array (
     [path] => ''  
    [contentTitle] => ''
    [ref] => ''
    [city] => ''
    [rif] => ''
    etc etc
#5

[eluser]daweb[/eluser]
Ok,

but... is it rigth to do that in the view, using the template parser class?

Code:
<div class="primary results">
<h2 class="title">Ricerca</h2>
[b]&lt;?php if($entries) : ?&gt;[/b]
<div class="info-results">
<div>{content_title}</div>
</div>
{entries}
<div class="apartment{list_class}">
<a class="image" href="{entry_url}"><img src="{photo_url}" alt="{entry_title}" /></a>
<div class="details">
<strong><a href="{entry_url}">{entry_title}</a></strong>
<span class="price">{entry_price}</span>
{entry_expert}
<a class="button" href="{entry_url}">vedi scheda</a>
<br class="clearer" />
</div>    
<br class="clearer" />
</div>
{/entries}    
[b]&lt;?php else: ?&gt;[/b]
<div>No</div>
[b]&lt;?php endif; ?&gt;[/b]
</div>

<div class="sidebar">
&lt;?php $this->load->view('commons/'.$this->config->item('set_front_lang').'/_search_form'); # include il form di ricerca ?&gt;
</div>
#6

[eluser]roj[/eluser]
Well, you could use it that way or else to keep all logic out of view files you could put the &lt;?php if($entries) : ?&gt; in the controller and then have a view file for if there are results and another for if there are non. That way removing the problem of the variable names showing up altogether....

So you would then have

Controller:
Code:
if ($entries)
{
$page = $this->parser->parse('search_results', $data, TRUE);
}
else
{
$page = $this->parser->parse('search_results', $data, TRUE)
}

$page .= $this->parser->parse('commons/'.$this->config->item('set_front_lang').'/_search_form', TRUE);

// Now output the page
$this->output->set_output($page);

With a View file for search results
Code:
<div class="primary results">
<h2 class="title">Ricerca</h2>
<div class="info-results">
<div>{content_title}</div>
</div>
{entries}
<div class="apartment{list_class}">
<a class="image" href="{entry_url}"><img src="{photo_url}" alt="{entry_title}" /></a>
<div class="details">
<strong><a href="{entry_url}">{entry_title}</a></strong>
<span class="price">{entry_price}</span>
{entry_expert}
<a class="button" href="{entry_url}">vedi scheda</a>
<br class="clearer" />
</div>    
<br class="clearer" />
</div>
</div>

And a view file for no search results
Code:
<div class="primary results">
<h2 class="title">Ricerca</h2>
<div>No</div>
</div>

By doing the above you'll keep all logic separate including the loading of the sidebar view...
#7

[eluser]daweb[/eluser]
Right.

Thank you so much.
#8

[eluser]roj[/eluser]
Glad to help




Theme © iAndrew 2016 - Forum software by © MyBB