Need to check if a Fuel Block exists

edited July 2012 in Modules
I have a use case where I would like a default banner to appear on every page, unless Fuel finds a page-specific banner in the _blocks/banners directory. Here is the code to generate this:

<?php $page = uri_string(); ?> <!-- Page Banner --> <div id="banner-wrapper"> <div class="page-banner"> <?php if(empty(fuel_block('banners/' . $page))): ?> <?=fuel_block('banners/default'); ?> <?php else: ?> <?=fuel_block('banners/' . $page)?> <?php endif; ?> </div> </div>
This code gives me the error: Can't use function return value in write context. I'm wondering is there a function in Fuel or Codeigniter that I can use that simply checks to see if a particular view file exists, either in the CMS or on the file system?

Thanks,
Erik

Comments

  • edited 6:23AM
    php's file_exists() function could work for you? If it doesn't, load default..
  • edited 6:23AM
    Fuel block will return FALSE if the file doesn't exist. So you could try setting it to a variable and then checking the variable's value too.
  • edited 6:23AM
    Thanks so much for the tip! That's all I needed to know. I've rewritten the above code to look like this in my page-banner.php view file:

    <?php $page = uri_string(); $fuel_block = fuel_block('banners/' . $page); ?> <!-- Page Banner --> <div class="banner-wrapper"> <?=($fuel_block) ? $fuel_block : fuel_block('banners/default')?> </div>

    Works perfectly and exactly as intended! Thanks!

    Erik
Sign In or Register to comment.