
Custom attributes and the color picker in the Online Editor 5.0
One of the many new features in the upcoming Online Editor 5.0 is the support for GUI interaction for the selection of custom attributes. Together with custom tags, this provides many possibilities. Consider the following example, where we want to have a few words or sentences within a paragraph to be a different color or style.
One of the custom attribute types is the color picker, which I will demonstrate in this post. Our test setup will use a standard eZ Publish 4.0.x installation with the Website Interface 1.3 and a pre-release of the Online Editor 5.0.
Custom tags
Let's start by defining a custom tag called “span”. I will not cover this in much detail as custom tags are well described in the online documentation and the basic setup has not changed since the Online Editor 4.0. The most important thing here is to tell eZ Publish that our new custom tag will be used as an inline element. We will do this by adding the following settings to settings/override/content.ini.append.php
[CustomTagSettings] AvailableCustomTags[]=span IsInline[span]=true
In the Online Editor 5.0, the "insert custom tag" dialog box will look something like this (note that there is still more configuration to do later to get the "Color" attribute to display as shown):
This is how the Online Editor renders an inline custom tag element:
Here is a preview of the output on the front-end of the site:
Next, we will create a span.tpl template in extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags with following content:
<span {if is_set( $color )}style="color: {$color}"{/if}>{$content}</span>
Now we are done with the custom tag configuration.
Custom attributes
Now that we have our template ready, we need to configure a custom attribute “color”. To do so, we add the following settings to the settings/override/content.ini.append.php file:
[span] CustomAttributes[]=color CustomAttributesDefaults[color]=#FF0000
The CustomAttributesDefaults setting specifies a default attribute value when the custom tag is first inserted.
Online Editor custom attribute types
We are almost done. Now let's take a look at the new custom attribute configuration features. Settings for this are stored in ezoe_attributes.ini, so we need to create our new configuration file in settings/override/ezoe_attributes.ini.append.php. In this file, we will specify that the Online Editor should use the color picker for our "color" custom attribute:
[CustomAttribute_span_color] Name=Color Type=color
The first line defines a block where the first item (“span”) is the custom tag name, while the second item (“color”) is the custom attribute name. The "Name" setting enables us to insert a human-readable name for the attribute when it is displayed in the "insert custom tag" dialog box. The value of the "Type" setting informs the Online Editor that we want to use a color picker.
Full details about the new Online Editor 5.0 custom attribute settings can be found in extension/ezoe/settings/ezoe_attributes.ini.
Below is a screenshot of the user interface for the color picker.
Remember to clear the cache before testing!

Comments

I cannot save colored text...
look like ezpublish has deleted my custom tag after i save the content! anybody help me resolve this problem?
thank for any help!

Right place..?
The right place of any coding is where developer puts it! The right place for javascript is in js file, but you still put it in any code page you need, correct?
Coloring is not a bad thing, especially for webs meant to aim children related "auditory", etc., etc. If you do not like it - do not use it!

Thank You
Thank You one more time your blog have the best tutorials for ez one to add is that for we changes
[CustomAttribute_span_color]
Name=Color
Type=color
had to be added into ezoe_attributes.ini.append.php not ezoe_customattributes.ini.append.php :)
Thank you

re: oe...
Thanks for comment. <span> is just an example of how you can use a custom attributes GUI in new OE. And it it only way to have a colorized sentence in color which editor choose from a color picker. It does not make sense to save a color with a dedicated class name in external CSS file. As color here is a dynamic value. You can have custom attributes which are CSS class names. For example <span class="{$class}">{$content}</span>, or <div class="{$class}">{$content}</div> or what ever XHTML markup you want, it is up to you, this can be either a predefined drop down box ("list") or a text filed where you can type class name. On almost ever pre-sale meeting I heard from customers "How can I have a one sentence in red and blinking?". Here is one example how can this be achieve in eZ Publish way. This feature has to be enable by site developer/administrator. So your comment is not really valid. It is up to site builder, not every site setup require such feature. The main goal behind this post is to show new OE feature related to custom attributes.

oe...
One of the best eZ Publish feature is Online Editor that doesn't allow to create stupid "colorized" texts.
Semantic texts with paragraphs, lists, links, a little bit of bold and italic and including objects was really great.
For now we will see a lot of ezp-sites with publications coloured with all rainbow colors.
It is possible to create coloured parts of text with blocks and styles. What is the reason to allow such things like this:
style="color: {$color}" ?
Right place of style is css file, isn't it?






Custom color chart
Friday 26 February 2010 12:52:45 pm
Philip
Hi there,
is there a possibility to create a custom color chart? Would be nice e.g. if you want the editors to only use colors from a companys corporate identity...
Thanks for your help!
Philip