I have a template that outputs certain articles from some categories as plain text files.
just about everything is working fine, with the only exception being that the article is rendered as one long line.
Now, my solution would be to write a plugin (lets call it ee:linebreak for now) that takes a number as an argument (say 80) and inserts a \r\n when it reaches that count and keeps doing that until the article is done, thereby breaking the article into many lines instead of one.
what I am looking for is the following:
1.) is my reasoning sound? That is, would it work like that or are there better, easier, faster approaches?
2.) how would I write this plugin? Do I hook into typography?
any other points would be greatly appreciated.
Kerim,
Sounds good to me. I might check to make sure this doesn’t already exist first.
Your plugin would not need to hook into the Typography class.
I’m thinking maybe it would wrap the article in the template and would strip any HTML out of the resulting $TMPL->tagdata.
Then you would go through do the line breaks after it has been cleaned out.
Make sense?
Jamie
Jamie,
thanks for the pointers; they make a lot of sense. I am already using the truncate HTML plugin and it is working fine. Yes, it does strip the images too, but then again, since it is only plain text output, I am fine with that.
When you say “go through and do the line breaks”, do you have a special function in mind? I figure that just counting the length of the string itself would not do me much good.
I am kinda stuck there, any help, even if it is just a function name, would be greatly appreciated!
Kerim,
Take a look at the Character Limit and Word Limit plugins in the Add-On Library to see how others have done similar things.
You want to do similar sort of thing except you want to add a line break after your limit instead of truncating the text. You also probably want to preserve words (unless you use a - to end a word that gets cut in half).
There isn’t really a single function that is going to do this for you. You will likely be using str_len, explode and count. You probably want something similar to the Word Limit Plus plugin but in a loop of some kind. You will also want to keep track of both words and characters in a line (thus why you have str_len as a probable function).
Jamie
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.