Adding classes to text boxes

scott's Avatar


20 Jun, 2012 09:37 PM

it would be really helpful if there was a simple way to assign a css class to text boxes just to have some options in how you want to display various types of text information. Just a thought.

  1. Support Staff 1 Posted by Mikael on 21 Jun, 2012 05:39 PM

    Mikael's Avatar

    I don't know how this could be implemented in an elegant way. It would require having some sort of title field for each textbox or something, which doesn't really make sense, since the only purpose would be to add an id or class to the HTML.

  2. 2 Posted by Philip Battin on 17 Sep, 2012 12:56 PM

    Philip Battin's Avatar

    I've also thought of this as a very powerful and useful feature. I often find myself doing all sorts of hacks to come around a solution like this. It could be implemented just like the way you chose what kind of displayer you want for your image group. Imagine a setup functionality where you can define a list of different classes for your text fields.

  3. Support Staff 3 Posted by Mikael on 27 Sep, 2012 08:28 PM

    Mikael's Avatar

    Hmm that's pretty nice actually...not bad.

  4. 4 Posted by Simon on 29 Sep, 2012 10:51 AM

    Simon's Avatar

    I've had this problem as well and solved it by creating a tag similiar to the code tag.

        hook( "pageTextModify", "sideBarBlock", "", 1 );
        hook( "blogPostModify", "sideBarBlock", "", 1 );
        hook( "textblockModify", "sideBarBlock", "", 1 );
        function sideBarBlock( $text )
            $pattern = "@{sidebar}(.*?){/sidebar}@s";
            $subject = html_entity_decode($text['original']);
            preg_match_all( $pattern, $subject, $matches );
            foreach ( $matches[1] as $match )
                $modified= preg_replace( "@^\n@", "", $match );
            $text['modified'] = $modified;
            $text['class'] = 'sidebar';
            return $text;

    I saved this as sidebarblock.plugin.php in cms/system/plugins.
    I also modified line 395 in cms/system/modules/projects/view.php to being:

    $print_block= '<div class="textblock ' . $textblock["class"] . '">' . $textblock['modified'] . '</div>';

    This could be done much more elegant by instead of wrapping the textblock in {sidebar}{/sidebar} using something like {class=sidebar} at the beginning and parsing that. Mikael, if the change to view.php could be made permanent I would improve my plugin and it could be shipped in a new version.

    Best, Simon

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac