Hiya,
In response to this thread over here I wanted to see if I could figure out a way to do it so I went ahead and tried. After around 2 hours of banging my head against the wall trying so many different variants I got it to work!!
Anyway plugin is attached to this post and usage is shown below and in the plugin documentation found in the admin area of EE.
Hope it’s of use to someone somewhere. Please do let me know if you use it on any projects as it’s always nice to hear / see what people are doing with these things!!
Best wishes,
Mark
UsageVariables class=”my-class” class you want applied to the span tag start=”1” which word in the string you would like to start from words=”2” how many words after the word you start from you would like to apply the class to{exp:mb_style_words class="first-word" start="1" words="2"} This is some text and I want the first word to be in capitals {/exp:mb_style_words}
EDIT: No more problems with the plugin, at least I don’t think so! 😉
Okay just found something out!
If you do this :
{exp:style_first_word}This is some text to process{/exp:style_first_word}
it outputs as you would expect!
Why would doing that and putting everything on one line stop the line-break?
Thanks again for any help on this.
Best wishes,
Mark
Okay a quick update to all of this and a new version.
Thanks to inparo in this thread the plugin is now much leaner.
Having said that I have gone ahead and updated the plugin to add in two more parameters (words=”1” and start=”2”).
They can be used as shown below :
{exp:first_word class="first-word" start="1" words="2"}
This is some text and I want the first word to be in capitals
{exp:first_word}
Variables class=”my-class” class you want applied to the span tag start=”1” which word in the string you would like to start from words=”2” how many words after the word you start from you would like to apply the class to
This means that now you could start from any place in the string and then carry on for however many words you wish to.
Slightly more power then! 😉
Updated file in top post!! 😉
Best wishes,
Mark
Nice. Right now, I’d love to have something similar that is character-based, i.e. to style the first x characters of a span.
Okay, give this one a try then!! 😉
Best wishes,
Mark
Don’t forget to link in the other post if you have somewhere you can show this in action as it is always nice to see it in working! 😉
Also let me know if you have any problems with it.
Best wishes,
Mark
Quick update for anyone reading this thread.
Plugin has now had a cosmetic name change and so the plugin tag is slightly different. For anyone new reading this thread then nothing will seem as though it has changed and you can just go ahead and download the version from the top post. Anyone who has already downloaded and downloads the new version you just need to change the name of the plugin tag to the one shown in the documentation above.
Best wishes,
Mark
Well it’s Monday morning and I thought I would have to build this plug-in myself, now I don’t so ‘Mark Bowen’ == Awesome.
Here is something that it’s missing though:
I want to style my title tags (as this script does) but instead of the first word I want the first half of the words example:
{exp:first_word class="first-half" start="1" words=".5"}
One Two Three Four Five Six
{exp:first_word}
outputs:
<span class="first-half">One Two Three</span> Four Five Six
It’s easy to grab the array length of the words, I’d write it so that the script rounds down when an odd number of words is inserted into the array.
FYI: you have a hidden “__MACOSX” folder in your plugin zip file
Don’t you just hate it when that happens? 😉
Does it cause problems with PCs then?
I will look into adding in the first-half feature that you want but can’t promise how quickly I will do that as really busy at the moment with my works web-site.
Best wishes,
Mark
Does it cause problems with PCs then?
Doesn’t cause any problems on Linux it just is visible. (It’s just a pet peeve of mine thumbs.db and __MACOSX files)
I’m not worried about the speed of the feature I could write it myself and post it here for you, but I shouldn’t need it till the end of the week.
To make the plugin more versatile for others, you should allow a percentage variable which will accept a percentage of words to place in a span(might be handy for your character style plugin as well). It also might be a good idea to place the remainder of string into a second span (I’ve not thought this through yet).
Okay, I’ve thought of another feature.
If the string only contains one word use your character plugin
for example:
{exp:first_word class="first-half" start="1" words=".5"} OnlyOneWord {exp:first_word}
outputs: OnlyOneWord
I’ve noticed I have a lot of one word headings and they are only one colour which really takes away from the graphic design of the site.
I’ll probably think of some more features in a few hours.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.