tag:help-archives.hannonhill.com,2010-02-09:/discussions/how-do-i/17557-text-area-max-lengthCascade CMS: Discussion 2015-05-04T21:09:24Ztag:help-archives.hannonhill.com,2010-02-09:Comment/366468812015-04-22T16:35:36Z2015-04-22T16:35:47ZText Area Max Length<div><p>Hi Jacob,</p>
<p>Unfortunately, I don't believe it's possible to limit the number
of characters of a text area field via the Data Definition
configuration. What you can do is modify your Format such that it
outputs only the first 'x' characters from that field, then it
outputs something like a 'read more' link. Let me know if you are
using XSLT or Velocity and I'll try to track down a sample Format
for that language.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/366468812015-04-22T16:52:51Z2015-04-22T16:52:51ZText Area Max Length<div><p>I'm using velocity for my formats.</p>
<p>Ya I looked for format solutions to my problem but I couldn't
get finding a string's length to work. Using .size() wasn't doing
the trick.</p>
<p>While we are talking about using a format for this issue, do you
think something similar could be done with a WYSIWYG? If so, that
may be preferable vs a text area. However, couldn't there be an
issue of removing closing tags (like ,,etc) that are in the end of
the string that is removed?</p>
<p>Ok, I'm rambling now. Thanks for the help!</p></div>Jacob V.tag:help-archives.hannonhill.com,2010-02-09:Comment/366468812015-04-22T17:59:59Z2015-04-22T17:59:59ZText Area Max Length<div><p>Hi Jacob,</p>
<blockquote>
<p>Ya I looked for format solutions to my problem but I couldn't
get finding a string's length to work. Using .size() wasn't doing
the trick.</p>
</blockquote>
<p>To get the length of a string, you would use the
<code>length()</code> method. For example:</p>
<pre>
<code>#set ( $str = "some string" )
## Outputs '11'
$str.length()</code>
</pre>
<blockquote>
<p>While we are talking about using a format for this issue, do you
think something similar could be done with a WYSIWYG? If so, that
may be preferable vs a text area. However, couldn't there be an
issue of removing closing tags (like ,,etc) that are in the end of
the string that is removed?</p>
</blockquote>
<p>You can definitely truncate WYSIWYG content issue; however, as
you indicated, you will need to deal with HTML tags and properly
closing them after the truncation occurs.</p>
<p>If generating unclosed tags is not of concern, you can use the
<a href="http://www.hannonhill.com/kb/Script-Formats/#display-tool">Display
Tool</a> to truncate the contents of the WYSIWYG (generated using
the Serializer Tool).</p>
<p>If you are concerned about closing the open tags, you have a
couple of options:</p>
<ul>
<li>Remove all tags from the content using the Display Tool
<code>stripTags</code> method and then truncate the resulting
text</li>
<li>Implement a way to parse through the tags and close them during
truncation. I actually <a href="https://gist.github.com/rgriffith/6082384">worked on a Velocity
macro</a> for another client that would abbreviate/truncate a
string that contains HTML tags and will attempt to close any that
are left open during the process. Feel free to give this a try if
you are interested. To use the macro, include it within your Format
and use it as follows:
<pre>
<code>#set ( $content = $_SerializerTool.serialize($wysiwygField, true) )
#abbreviateHtmlString($content, 500, true)
<p><a class="readmore" href="${link}">Read more...</a></p></code>
</pre></li>
</ul>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/366468812015-04-22T21:12:56Z2015-04-22T21:12:56ZText Area Max Length<div><p>Ryan,</p>
<p>I decided to use a WYSIWYG with the Macro you linked and it
worked like a charm. I did need to change it just a bit so that the
max length was based on character count rather than word count, but
other than that there were no major changes.</p>
<p>I just want to say that you have helped me more times than I can
count with all of the posts on these forums. You da man!</p></div>Jacob V.tag:help-archives.hannonhill.com,2010-02-09:Comment/366468812015-04-22T21:36:37Z2015-04-22T21:36:57ZText Area Max Length<div><p>Hi Jacob,</p>
<p>Ryan is out this afternoon. Thanks for the kind words. I will
definitely pass the message along to both him and his team.</p>
<p>Have a great afternoon.</p></div>Bradley Wagnertag:help-archives.hannonhill.com,2010-02-09:Comment/366468812015-04-23T16:14:24Z2015-04-23T16:14:24ZText Area Max Length<div><p>Hi Jacob,</p>
<p>Just iIn-case you did not notice and changed the macro's code,
the macro does accept a third parameter which is a flag to choose
to truncate by number of words or number of characters. That is,
passing <code>false</code> as the third parameter would indicate
number of characters and <code>true</code> would be number of
words.</p>
<p>So you would adjust the code I provided to the following:</p>
<pre>
<code>#abbreviateHtmlString($content, 500, false)</code>
</pre>
<p>Again, thank you for the kind words and let us know if you have
any other questions.</p>
<p>Have a great day!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/366468812015-04-23T16:23:56Z2015-04-23T16:23:56ZText Area Max Length<div><p>Whoops, I didn't realize. I suppose I just made it a bit harder
on myself, but anyways thanks for the clarification.</p></div>Jacob V.tag:help-archives.hannonhill.com,2010-02-09:Comment/366468812015-04-23T18:11:46Z2015-04-23T18:11:46ZText Area Max Length<div><p>Not a problem at all, Jacob. If your change is better than what
I had, please feel free to share and I'll update the <a href="https://github.com/hannonhill/Velocity-Cookbook/blob/master/Macros/abbreviateHtmlString.vm">
macro in our Velocity Formats examples project</a> on Github.</p>
<p>Thanks!</p></div>Ryan Griffith