• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Template Parser, if statement?


Let me start out by saying I'm new here Wink I've recently started learning CI and have had some fun with it so far... Anyhow...

I'm using the template parser with data from mysql. Some columns may or may not be null... My question is, is there a way to check if the var is empty without using regular php? for example, with foreach I know I can use:


I'm trying to get around outputting a bunch of empty html tags for columns that are null, while keeping the view files as clean as possible.


Welcome to CI!

First question I would have is are you sure you need to use the Template Parser? If you don't really need it (like for working with designers who you're afraid might accidentally break it) then I would just go with straight PHP for the entire page. It's less resource-intensive and will perform faster.

[eluser]saidai jagan[/eluser]
In smarty,
{if $result_arr|count > 0}
// some codes
// No records found

[eluser]Phil Sturgeon[/eluser]
If you really must, here is one way.

You could always try using Dwoo for your CodeIgniter views? It is similar to Smarty, but much quicker seamlessly integrates with the Parser class.

@kilishan - Yes, I def need some sort of Template Parser... I will be having designers work on it Wink

@saidai - smarty would be nice... i just feel that it's a bit too much for the project...

@phil - After taking a look at the second option... I'm going to give that a try!


EDIT: Nevermind! I didn't realize I needed to add dollar signs to my views... thx Wink

@phil - I'm trying to use your dwoo implementation but am a little stuck... this works fine:
$this->parser->parse('dwoo_test', array('message' => 'OH HAI!'));
but when my existing code:
$data = array(
    'search_terms' => $search_terms,
    'search_location' => $search_location,
    'first_result' => @$first_result,
    'last_result' => @$last_result,
    'total_results' => @$total_results,
    'search_results' => @$results,
    'search_pagination' => $this->pagination->create_links()

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

i get the following error:
Fatal error: Uncaught exception 'Dwoo_Exception' with message 'Plugin <em>search_terms</em> can not be found, maybe you forgot to bind it if it's a custom plugin ?'
in C:\www\htdocs\newsite\application\libraries\dwoo\Dwoo\Loader.php:111 Stack trace: #0 C:\www\htdocs\newsite\application\libraries\dwoo\Dwoo\Compiler.php(2866):
Dwoo_Loader->loadPlugin('search_terms', true) #1 C:\www\htdocs\newsite\application\libraries\dwoo\Dwoo\Compiler.php(1633): Dwoo_Compiler->getPluginType('search_terms')
#2 C:\www\htdocs\newsite\application\libraries\dwoo\Dwoo\Compiler.php(1302): Dwoo_Compiler->parseFunction('<!DOCTYPE html ...', 1668, 3507, false, 'root', 1680) #3
C:\www\htdocs\newsite\application\libraries\dwoo\Dwoo\Compiler.php(758): Dwoo_Compiler->parse('<!DOCTYPE html ...', 1668, NULL, false, 'root', 1680) #4
C:\www\htdocs\newsite\application\libraries\dwoo\Dwoo\Template\String.php(369): Dwoo_Compiler->compile(Object(Dwoo), Object(Dwoo_Template_String)) #5
C:\www\htdocs\newsite\application\librari in C:\www\htdocs\newsite\application\libraries\dwoo\Dwoo\Loader.php on line 111

what am i doing wrong?

[eluser]Phil Sturgeon[/eluser]
Are you using the correct Dwoo syntax?

{search_terms} will break, but {$search_terms} will work fine. Dont forget the $ at the start. :-)

Yeah, I figured it out Wink Thanks!

One more Question though... Is there something special I need to do to use:
{extends "main_view"}
? I just get a white screen with the name of the view I'm "extending". I'm using
$this->parser->parse('some_view', $data);
to load a view. That view contains the above mentioned "extends". I know the syntax is correct... I have even used the default "test" views that come with the dwoo CI Adapter and get the same result. And if it matters, I tried using the adapter and "extends" worked fine...

Thanks again!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.