XReadMore ¶
A widget to shorten html content to a certain length, and give a link to read for the full text.
Use ¶
Simple case ¶
In the view add:
<?php
$this->widget('ext.XReadMore.XReadMore', array(
'model'=>$data,
'attribute'=>'Content',
));
$this->widget('ext.XReadMore.XReadMore', array(
'showLink'=>false,
'model'=>$data,
'attribute'=>'Content',
'maxChar'=>100,
));
?>
Other Uses ¶
There are some other parameters that could be set. The following are the list of all parameters that could be set with the widget.
public $showLink = true; // Show link to go to full text page
public $model = null; // the data model, if set use model->attribute for long text, defaults to null
public $attribute = null; // the attribute
public $text = null; // the long text, model proprty should be null to use this
public $stripTags = true; // determines whether to return plain text or html text
public $maxChar = 400; // the maximal count of character before it is truncated
public $separator = " "; // the separator to use after maxChar is satisfied
public $linkHtmlOptions = array(); // link html options.
public $allowedTags = '';
public $charset = 'UTF-8';
public $linkText = 'Read more...'; // link label, default 'Read more...'.
public $linkUrl = null; // link url.
public $return = false; //if short version will be returned or echoed.
Thanks to Usui eitalian@mail.ru for adding selective tag and encoding support.
Nice
Thanks for this. I had come up with same approach but mine looks for the period not number of characters. I will use it soon in my project.
separator
I am glad to know that this is helping someones else in their project :)
This extension actually uses a character too to do the split. In this case it uses a space character by default, but if you prefer a different character, you may set it with the separator property.
So, actually this extension searches for a character after a certain number of characters is met. Originally this is done so the split wouldn't happen in the middle of a word or something.
HTML?
How does it cut HTML? Does it automatically close tags?
short html
@pmaselkowski
I am not sure what you mean by cut html. In this case, I'll assume you meant by shortening html text. This extension just counts a certain length of characters and extracts the html. As for closing the tags, the result is then purified with html purify to fix broken tags. So far, it worked okay in my case.
Alternative method/suggestion
Hi
Your extension reminded me of a technique I put in place so I described it here.
Maybe it'll spark an idea to propose a formatter with your extension.
Formatter
@letop
That's a nice idea. I did plan to make this not just to be a widget but also a filter, but since currently this works okay in my case, i might extend it more later. That's a good idea. Maybe if you have the resources and interested to extend this extension, I could set up a github account for this.
How to use
I am getting error when using this widget, or am I doing it incorrectly
What am I to put inside the model, attribute, and linkurl.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.