Searching through widget code in dotCMS

If you have ever worked with the popular content management system dotCMS, you may have discovered a few quirks and annoyances along the way. One such small (but time consuming) pain point is the inability to search through code in custom widgets. However, what you may not realize is that widgets are nothing more than a special content structure. As a structure, everything in a widget, even the HTML and Velocity code, is stored in a field in the database, which means the code is in fact searchable.

There are two ways to search through widget code, but you may need administrator access to use them.

Method 1: Use the Query Test Tool

Under the CMS Admin tab, click Query Test Tool. Use a Lucene query like the following one the “code” field:

+structureName:application +deleted:false +working:true +application.widgetTitle:* +application.code:*

For example, to search for widgets containing a reference to tags in the code, you could look for:

+structureName:application +deleted:false +working:true +application.widgetTitle:* +application.code:*tag*

Method 2: Customize the Applications Structure

Under Structures, edit Application (Simple Widget). Edit the Code field (not Widget Code!) and select the “User Searchable” option. This will allow searching for code through the left pane as you would in any other structure, making it easier to perform searches. However, this also comes at a price: all code must now be indexed. For large blocks of code, this may result in slower searches.

These two methods provide easy ways to search through code in dotCMS widgets. Although modifying a search query seems slightly more difficult, indexing blocks of code may also be overkill, particularly if you do not need to search for code often.

About Gabriel Mongefranco

Gabriel Mongefranco is your software developer for all things data: extraction, integration, analytics and security. He is also a blogger, a poet, a proud father and a faithful Christian. He is always eager to contract with faith-based nonprofits! Learn more.