Stuck on making template for Express List Block - Showing images (continuing thread from old forum)

Context:
I posted on the old forums asking about customising the Express List Block to make it so that the “Image” Attribute type of an Express Entry shows the image graphic itself, instead of the hyperlink to the image file (which is not useful lol). Original thread here : Stuck on making template for Express List Block - Showing images - concrete5

@mnakalay was helping me in that thread.

I’m starting this thread to continue it.

Firstl, the code snipping that @mnakalay posted at the end worked for me so far! I need to tune it more as I think my own work has broken the processing of the rest of the columns after the image file, plus there’s a typo in the code that @mnakalay posted. The “” part has one too many closing brackets and instead should be “

That being said, yay! Thanks @mnakalay !

I may continue to seek help in this thread with what I’m trying to do here, but right now it looks to work for me :smiley:

Sorry that it took so long for me to test it, one month + one day to the day, life has been a bit chaotic. But @mnakalay 's help is very much appreciated! Hopefully this can help others too. Here’s the original code-block posted from them (with the correction). This is for the view.php, starting at line 98 in the original unmodified view.php file, for those that want to implement it in the future:

<?php 
$entry = $item->getEntry();
foreach ($item->getColumns() as $column) {
    $columnKey = $column->getColumnKey(); // ak_some_attribute_handle
    $attrHandle = substr($columnKey, 3); // remove the ak_ to get the attribute's handle
    $category = $entity->getAttributeKeyCategory(); // get the attribute category (here it's Express)
    $attribute = $category->getAttributeKeyByHandle($attrHandle); // get the attribute object now that we have its handle and its category
    // some columns are not for attributes but for other objects like associations or default fields so make sure you do have an attribute before getting its type
    if ($attribute && is_object($attribute)) { 
        $attrTypeHandle = $attribute->getAttributeTypeHandle();
        if ($attrTypeHandle == 'image_file') {
            $fv = $entry->getAttribute($attribute);
            if (is_object($fv)) {
                ?>
                <td><img src="<?=$fv->getURL()?>"></td>
            <?php
            }
        }
    }
} // end foreach item->getColumns

This is actually the full section of code (plus some before and after that I didn’t modify) starting line 93. I’ve left the comments in for the time being, but they’re not necessary. I may do more modifications as I go, but this is to get that image type showing image instead of URL, and this is the full code that worked for me. Again thanks @mnakalay ! Hopefully this helps others, again starting at Line 93 of the default view.php for the Express List Block:

            <tbody>
            <?php
            $rowClass = 'ccm-block-express-entry-list-row-a';
            foreach ($result->getItems() as $item) { ?>
                <tr class="<?=$rowClass?>">
                <?php
                $entry = $item->getEntry();
                foreach ($item->getColumns() as $column) {
                    $columnKey = $column->getColumnKey(); // ak_some_attribute_handle
                    // Test line below
                    echo $columnKey . '<br>';
                    $attrHandle = substr($columnKey, 3); // remove the ak_ to get the attribute's handle
                    $category = $entity->getAttributeKeyCategory(); // get the attribute category (here it's Express)
                    $attribute = $category->getAttributeKeyByHandle($attrHandle); // get the attribute object now that we have its handle and its category
                    // some columns are not for attributes but for other objects like associations or default fields so make sure you do have an attribute before getting its type
                    if ($attribute && is_object($attribute)) { 
                        $attrTypeHandle = $attribute->getAttributeTypeHandle();
                        // do your stuff with $attrTypeHandle
                        // BELOW IS TESTING LINE
                        echo $attrHandle . ' ' . $attrTypeHandle . '<br>'; //TESTING LINE FOR MNAKALAY
                        // ABOVE IS TESTING LINE
                        if ($attrTypeHandle == 'image_file') {
                            $fv = $entry->getAttribute($attribute);
                            if (is_object($fv)) { ?>
                                <td><img src="<?=$fv->getURL()?>"></td>
                            <?php
                            }
                        } else { ?>
                            <td><?=$column->getColumnValue($item);?></td>
                        <?php
                        }
                    } elseif ($controller->linkThisColumn($column)) { ?>
                        <td><a href="<?=URL::to($detailPage, 'view_express_entity', $item->getEntry()->getId())?>"><?=$column->getColumnValue($item);?></a></td>
                    <?php
                    } else { ?>
                        <td><?=$column->getColumnValue($item);?></td>
                    <?php
                    }
                }
                $rowClass = ($rowClass == 'ccm-block-express-entry-list-row-a') ? 'ccm-block-express-entry-list-row-b' : 'ccm-block-express-entry-list-row-a';
                ?>
                </tr>
            <?php } ?>
            </tbody>
        </table>
1 Like