Express List - Custom Template: individual CSS classes for ColumnValues
Permalink
I'm working on a custom template for the express_entry_list block, and i'm trying to add CSS classes to the attribute items of the results, because i want to be able to style the output differently. I have changed the default table markup to div containers, and now i want to have each attribute output as div container with a separate CSS class, named after the handle of the attribute, like so:
So the output of an item shoud look like this:
Unfortunately i don't know how to get the attribute handle for each item. I have tried to get it by
but i don't know how to integrate that into the loop, but maybe it's a wrong approach anyway.
Can someone please help?
<div class="[attribute_handle]"><?php echo $column->getColumnValue($item);?></div>
So the output of an item shoud look like this:
<div class="ccm-block-express-entry-list-row-a"> <div class="firstname">Joe</div> <div class="lastname">Mayer</div> <div class="profession">Teacher</div> <div class="birthdate">05.10.1966</div> </div>
Unfortunately i don't know how to get the attribute handle for each item. I have tried to get it by
<?php echo $ak->getAttributeKeyHandle();?>
Can someone please help?
I found a simple solution, that also works as long as i'm building an Express Entry List template for each Data Object. So, when knowing the handles, actually i don't need to call them by a function, i can just dirty hardcode them as CSS class names, since this template can only be used for this specific Data Object anyway.
But what i'm looking for is a more elegant solution, a template for universal usage, without having to know the handles of the attributes, a function that retrives the attribute handles from inside the foreach loop, if this is possible.
But what i'm looking for is a more elegant solution, a template for universal usage, without having to know the handles of the attributes, a function that retrives the attribute handles from inside the foreach loop, if this is possible.
@okapi This was exactly what I was looking for to format a really specific express object list as blocks of individual data instead of a table format. Thank you!!
By the way, for image attributes (example handle here: photo_person) you would need something like this:
<?php $photoFileObject = $item->getEntry()->getPhotoPerson(); if (is_object($photoFileObject)) { $photoFileObjectVersion = $photoFileObject->getVersion(); $photoRelativePath = $photoFileObjectVersion->getRelativePath(); ?> <div class="photo-person"><img src="<?php echo $photoRelativePath; ?>"></div> <?php } ?>
Thank you so much, this works great now for text attributes!
I think it would get quite complex, if it also should check what type of attribute is processed, because an image for example needs some HTML around the output, in order to have it displayed as image, instead of just showing it's path, or a "mailto" parameter for email links...
I think it would get quite complex, if it also should check what type of attribute is processed, because an image for example needs some HTML around the output, in order to have it displayed as image, instead of just showing it's path, or a "mailto" parameter for email links...
@okapi
You could get the attribute type handle, then based on the handle decide how to process. A switch might work for that.
You could get the attribute type handle, then based on the handle decide how to process. A switch might work for that.
$attribute->getAttributeTypeObject()->getAttributeTypeHandle()
Here is something to try:
- This loops through the "Person" express object entries.
- The person entry attributes are looped over to display the attribute handle and attribute display value.
- The "get" magic methods are not used, so you don't need to know/enter the attribute handles.
- This should allow for a generic template to be created.