Choose between icon and image in Feature Block C5.7

Permalink
Working on a custom theme for Concrete5 5.7. I am trying to allow my client to choose between an icon or an image in the Feature block. I have successfully been able to enter an image into the database via the updated block. However, I can't figure out how to get the image to show. Below are my updates to the code. (FYI - I am learning PHP, so I mostly copied things from the "image" block to try and make the feature block work. There may be code that I don't need or things that I am missing).

Controller.php
<?php
namespace Application\Block\Feature;
use Page;
use File;
use Database;
use Concrete\Core\Block\BlockController;
use Less_Parser;
use Less_Tree_Rule;
use Core;
defined('C5_EXECUTE') or die("Access Denied.");
class Controller extends BlockController
{
    public $helpers = array('form');
    protected $btInterfaceWidth = 400;
    protected $btCacheBlockOutput = true;


Form.php
<?php defined('C5_EXECUTE') or die("Access Denied."); 
$al = Loader::helper('concrete/asset_library');
$bf = null;
$bfo = null;
if ($controller->getFileID() > 0) { 
   $bf = $controller->getFileObject();
}
?>
<fieldset>
    <legend><?php echo t('Icon')?></legend>
        <div class="form-group ccm-block-feature-select-icon" style="margin-right: 35px;">
            <?php echo $form->select('icon', $icons, $icon);?>
            <i data-preview="icon" <?php if ($icon) { ?>class="fa fa-<?php echo $icon?>"<?php } ?>></i>
        </div>
</fieldset>



View.php
<?php  defined('C5_EXECUTE') or die("Access Denied."); ?>
<div class="service span3">
<?php if($icon) { ?>
   <div class="icon-awesome">
        <i class="fa fa-<?php echo $icon?>"></i>
    </div>
<?php } ?>
<?php if (is_object($f)) {
        $image = Core::make('html/image', array($f));
        $tag = $image->getTag();
    } ?>
<?php if ($title) { ?>
        <h4><?php echo $title?></h4>
<?php } ?>
<?php if ($paragraph) { ?>


Any help would be appreciated, thanks!

 
MrKDilkington replied on at Permalink Best Answer Reply
MrKDilkington
Hi Freckles,

You can try this to display your image in view.php.
if (is_object($f)) {
    $image = Core::make('html/image', array($f));
    $tag = $image->getTag();
    // Optional:
    // add an alt tag to the tag object
    $tag->alt('this is my image of something');
    // Optional:
    // add a class to the tag object
    $tag->addClass('some-image-class');
    echo $tag;
}
Freckles replied on at Permalink Reply
Worked perfectly, thanks so much!