Limit characters in list view template

rowanwins

Member
Hi there,

I've just been making my first custom list view, its suprisingly easy! I've managed to bring in the fields I want however Im wondering if I can limit the number of characters shown in one of the fields.


<?php echo $this->_row->data-> groups___GroupDesc ;?>

I've also lost my details view button somehwere in the process of editing my default_row.php but in an ideal world I'd rather have something that says a bit of text saying 'Read more' or something like that, I sure there must be an easy way to add a link to the details view of the row.

Any tips?
Thanks in advance,
Rowan
 

Attachments

  • list view.png
    list view.png
    306.5 KB · Views: 345
In a textarea element you can "truncate" the list view text size (+ show the complete text by hovering).
An other possibility is to define a max width/height + overflow:hidden for the text (div, li...) via CSS.

Additionally re-add the details view button or enable "link to details" in element settings and in list setting set links to "ajaxfy", so a click on the details button or the text will open the details view in a popup.
 
Hi Troester,

Thanks for the tip, I hadn't noticed the truncate settings, having said that unfortunantly they dont seem to be working in my custom template, if I go back to the bootstrap template it works fine.

I wonder if I've stripped too much code out of my default_row.php file and thats what also causing the disappearance of the link to details button...

This is what I've currently got, I stripped it right back trying to get things to work but obviously I went a bit far :)
PHP:
<tr id="<?php echo $this->_row->id;?>" class="<?php echo $this->_row->class;?>">
   
        <td>
            <div class="span4"><?php echo $this->_row->data-> groups___GroupLogo ;?></div>
            <div class="span8"><h3><?php echo $this->_row->data-> groups___GroupName ;?></h3></div>
            <p><?php echo $this->_row->data-> groups___GroupDesc ;?></p>
        </td>
 
</tr>

Thanks
Rowan
 
Because the fields that are displayed in the template are already rendered, a template is not the easiest place (or the right place) to limit the length of the field contents.

I should caution you against using templates as a quick way of creating certain functionality - templates are supposed to work for all Fabrik applications and are supposed only to vary how the information is displayed, not what is displayed or any application functionality. Not only are you creating a potential maintenance headache for the future, but in my experience you risk e.g. creating disparities between the HTML (which is created in the template) and the Fabrik javascript code block (which is created elsewhere). See this thread for an example of where someone used a custom form template to provide application functionality (e.g. not to display certain elements in certain circumstances) and created such a disparity which caused the javascript to fail and the page to stop working.

Listing elements explicity (as above) rather than displaying all elements in a loop means that every time to change your List, you may also have to change the template. And when a GitHub update includes changes to the way templates work, you will have to retrofit those changes to your template.

If you can you should try to create all your functionality using standard Fabrik functionality and create your own Fabrik template only when you don't like the way it is being shown e.g. you want a group title in a side-bar, or the intro text in a tool-tip, or to limit every field to so many characters I think this would be a better approach.

So the (or at least one) correct way of limiting the number of characters is to use a calc field for the list display.

S
 
If you want to achieve a particular look then a custom template is the correct solution but try to keep it generic (i.e. not specific to any particular element(s)).

To get a return value, you need at the end:
PHP:
return $post;
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top