We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

NEW Plugin - MB Style Words…

Development and Programming

Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

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

Usage
{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}
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
       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

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

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

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

       
TheBrad's avatar
TheBrad
48 posts
17 years ago
TheBrad's avatar TheBrad

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.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen
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

       
TheBrad's avatar
TheBrad
48 posts
17 years ago
TheBrad's avatar TheBrad

Wow, thanks! Who’s awesome? You are!

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

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

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

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

       
nyeoman's avatar
nyeoman
94 posts
17 years ago
nyeoman's avatar nyeoman

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.

       
nyeoman's avatar
nyeoman
94 posts
17 years ago
nyeoman's avatar nyeoman

FYI: you have a hidden “__MACOSX” folder in your plugin zip file

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen
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

       
nyeoman's avatar
nyeoman
94 posts
17 years ago
nyeoman's avatar nyeoman
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).

       
nyeoman's avatar
nyeoman
94 posts
17 years ago
nyeoman's avatar nyeoman

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.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Hmm you may have to start adding these in yourself at this rate 😉

I will try and get something done on a couple of these in a few days but if you need them before then please feel free to add them in and post here what you have done 😉

Best wishes,

Mark

       
nyeoman's avatar
nyeoman
94 posts
17 years ago
nyeoman's avatar nyeoman

No worries, I’m busy today and tomorrow with graphic design and site structure. But I’ll for sure add these features when I get the chance. You have setup a good base so it will be easy for me to post my updates here.

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.