Use Rapido to create custom SearchableText field


Create TTW (Through The Web) a Book content type where fields are indexed for a full-text search.

Content type

Add a new content type Book on the Dexterity Content Types control panel (http://localhost:8080/Plone/@@dexterity-types).


Edit the Book configuration (http://localhost:8080/Plone/dexterity-types/book). In the Behaviors tab, uncheck the Dublin Core metadata behavior and Save. In the Fields tab, click on the Edit XML Field Model button and replace the XML model by:

<model xmlns:form=""
    <field name="title" type="zope.schema.TextLine">
    <field name="authors" type="zope.schema.Text">
    <field name="year" type="zope.schema.Int">
    <field name="isbn_13" type="zope.schema.TextLine">
      <title>ISBN 13</title>
    <field name="image" type="plone.namedfile.field.NamedBlobImage">
    <field name="back_cover" type="">
      <title>Back cover</title>

You can now add Book content in your web site (http://localhost:8080/Plone/++add++book).


Full text search field

If you have a lot of books in your site, you would like to search on the author’s name or the back cover content. To do this we have to provide a SearchableText method or field which give the content of the full-text index. We’ll use a rapido block and a rapido content rule action to compute this SearchableText field.

Rapido block

Go to the Theming control panel (http://localhost:8080/Plone/@@theming-controlpanel). Create a new theme MyTheme with this structure.


Look for example at the Inheriting a new theme from Barceloneta section of the Plone documentation for the content of index.html, manifest.cfg and rules.xml files.

Content of file:

def update_searchabletext_field(context):
    transforms = context.api.portal.get_tool(name='portal_transforms')
    book = context.content
    back_cover_html = book.back_cover.output if book.back_cover else ""
    back_cover_plain = transforms.convertTo(
        'text/plain', back_cover_html, mimetype='text/html').getData()
    book.SearchableText = " ".join([
        book.title if book.title else "",
        book.authors if book.authors else "",
        str(book.year) if book.year else "",
        book.isbn_13 if book.isbn_13 else "",

We use the portal_transforms tool to convert the back_cover HTML field to plain text. We also need to reindex the content.

Rapido content rule action

The last thing we need is a rapido content rule action which is used on each book modification.

Go to the Content Rules (http://localhost:8080/Plone/@@rules-controlpanel) and add a rule which is triggered on Object modified event.


Add a Content type condition on Book. Add a Rapido action.


Assign the content rule on the whole site and Save.



Modify the code above to compute a Description field which will be used in Plone listings.

Custom book view

To build a custom book view, the simplest solution is to use a Diazo rule.

For example, you can add in the rules.xml file of your theme the following diazo rule:

<rules css:if-content="body.template-view.portaltype-book">
  <replace css:content="#content-core" method="raw">
    <xsl:variable name="image_url">
      <xsl:value-of select="substring-before(//span[@id='form-widgets-image']/img/@src,'view')"/>
    <div class="row">
        <div class="col-xs-12 col-sm-4">
            <xsl:if test="$image_url">
                <img src="{$image_url}@@images/image/large" style="width: 100%;" />
        <div class="col-xs-12 col-sm-8">
            <div><strong>Author(s) : </strong><xsl:copy-of css:select="#form-widgets-authors" /></div>
            <div><strong>ISBN-13(s) : </strong><xsl:copy-of css:select="#form-widgets-isbn_13" /></div>
            <div><strong>Year : </strong><xsl:copy-of css:select="#form-widgets-year" /></div>
            <div><xsl:copy-of css:select="#formfield-form-widgets-back_cover" /></div>

Our new custom book views: