A simple Read more/less grails tag

10 / Mar / 2011 by Partho Ghosh 0 comments

Hello world.. In a pretty recent project, I was a given a task to implement “read more” custom tag to implement “read more” functionality (a block of text followed by a read more link. Block of text expands and collapses on clicking of a link). I will be honest over here.I did a pretty bad job and implemented the tag in a quiet dirty way. Later I found some time to work on it and end up creating something way better than previous effort 😀

Read More/Less tag

It is a pretty simple tag in which you pass a block of text and in return you get the text “read more/less”-ified (Ok! I know thats bad :P). Anyways, now for this tag to work, Jquery is required.

Tag syntax

Just enclose the block of text inside the “readMore” tag and you are done.

[java]
<ls:readMore>${myText}</ls:readMore>
[/java]

Output

After clicking the read more/less…

This tag can be used to create multiple “read more”s like following:

I believe there is still room for improvement in tag and will try to bring in as much as possible . You can download the code from the following link and play around with it if required. Feel free to advice me on how can I improve the tag or you can come up with your own improvements. Ciao

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *