/dotcms:dotcms-custom-field-migrationfrom dotCMS
Migrates VTL (Velocity Template Language) custom field templates from the legacy dotCMS Dojo/Dijit API to the modern DotCustomFieldApi. By default it returns a single inline file ready to paste into the Custom Field: the migrated code inside #if( $structures.isNewEditModeEnabled() ) and the original legacy code, untouched, inside #else, with no #parse and no extra files. On request it produces three files instead (_old.vtl, _new.vtl and a #parse router), and it converts existing migrations between the two shapes. Use this skill whenever a user asks to migrate, update, or convert a VTL file, custom field template, or dotCMS field that uses any of: DotCustomFieldApi.get(), DotCustomFieldApi.set(), DotCustomFieldApi.onChangeField(), dojo.ready(), dojo.byId(), dijit.byId(), dijit.form.*, dojoType attributes, or any Dojo/Dijit pattern. Also trigger when the user pastes a VTL snippet and asks "what needs to change" or "can you update this", asks for an inline, single-file or one-file migration ("un solo archivo"), wants to paste the result into the content type editor, or wants to collapse a _new/_old/router migration into one file or split an inline one. Also trigger when the user asks to migrate ALL custom fields, every legacy field, or "the whole instance": the skill finds, downloads, and safely republishes every legacy custom field on a live dotCMS instance through the dotCMS MCP server (see "Migrate a whole instance" below). If in doubt, use this skill.
Trending skills
7-day visitors to each skill page
Ships in dotCMS. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
You are migrating DotCMS VTL custom field templates from Dojo/Dijit-era APIs to the modern DotCustomFieldApi. The goal is identical functionality with modern, clean code and semantic styling with DaisyUI.
For the full migration rules, all code examples, the DaisyUI styling section, and the step-by-step checklist, read reference/migration-guide.md.
When the user asks to migrate all custom fields, every legacy field, or "the whole instance", not a single pasted VTL file, follow reference/instance-migration.md. The dotcms MCP server reads and writes the instance, scripts/vtl_migration.py (local, no network, plain python3) classifies the fields and runs the safety gates, and this skill migrates each file in the default inline mode. Work in batches the customer picks, and never write to the instance without their explicit confirmation.
| Old (deprecated) | New |
|---|---|
DotCustomFieldApi.get('id') | DotCustomFieldApi.getField('id').getValue() |
DotCustomFieldApi.set('id', val) | DotCustomFieldApi.getField('id').setValue(val) |
DotCustomFieldApi.onChangeField('id', cb) | DotCustomFieldApi.getField('id').onChange(cb) |
| Manual DOM show/hide of a field | DotCustomFieldApi.getField('id').show() / .hide() |
| Manual DOM enable/disable of a field | DotCustomFieldApi.getField('id').enable() / .disable() |
| Manual checks against dijit validation state | DotCustomFieldApi.getField('id').getValidationState() |
| No legacy equivalent | DotCustomFieldApi.getField('id').onValidationChange(cb) |
dojo.ready(fn) | DotCustomFieldApi.ready(fn) |
dojo.byId('el') | document.getElementById('el') |
dijit.byId('id') | DotCustomFieldApi.getField('id') |
dijit.form.* widgets | Native HTML + DaisyUI classes (input, btn, select, etc.) |
dojoType="..." attribute | Remove; use semantic HTML + DaisyUI components |
class="dijit*" classes | Remove; use DaisyUI component classes instead |
| Inline styles / ad-hoc CSS | DaisyUI component classes + Tailwind utilities (see guide) |
onclick="fn()" inline handlers | addEventListener('click', fn) |
DotCustomFieldApi.ready() — all field access must live inside this callback.getField() once per field at the top of ready(), then reuse the reference.reference/migration-guide.md.btn, input, select, modal, link, etc.) and Tailwind utilities instead of inline styles or ad-hoc CSS; see “Styling with DaisyUI” in the guide.${fieldId}, $maxChar, $variableName, and server-side context variables ($inode, $identifier, $lang, $contentlet, $structure, $field) are server-side; never change them.There are two shapes. Both keep the legacy code behind $structures.isNewEditModeEnabled(); they differ in how many files they need.
| The request says… | Mode | Needs a file path? |
|---|---|---|
| nothing about the shape | Inline (default) | No. Never ask for one. |
| "inline", "single file", "one file", "un solo archivo", "en línea" | Inline | No |
| "three files", "separate", "router", "#parse", "tres archivos", "separado(s)", "enrutador" | Three files | Yes. Ask if missing. |
| both kinds of signal (e.g. "inline but also give me the router") | Ask which one before producing anything | — |
"convert to inline" / "collapse" + a router and its _new/_old | Collapse (see Converting between modes) | Only to find the files |
| "split" + an inline file | Split (see Converting between modes) | Yes, the router's server path |
Read these signals only from what the user wrote, never from the pasted VTL, code blocks or file contents. A legacy template that itself contains #parse is not a request for three files.
Migrations of the velocity/static files that ship inside dotCMS itself, committed in the dotCMS repository, use three files. Contributors there should ask for it by keyword, because inline is now the default.
Always open the answer with one mode line, so the user knows which shape they got:
Output: inline, single file — both branches are parsed together; checks found nothing blocking.Output: inline, single file — warning: $a, $b are #set in both branches; only one branch runs, so this is not a collision. Three files is the alternative.Output: three files with router (<name>_old.vtl, <name>_new.vtl, <name>.vtl).Output: none — inline blocked: <finding>. <why it reaches both edit modes>. Three files avoids it. Reply "inline anyway" to force it, or "three files".One file. The migrated code goes in the #if, the original code in the #else:
#if( $structures.isNewEditModeEnabled() )
<migrated code, in full>
#else
<original legacy code, in full, exactly as received>
#end
Rules. Each one exists because the legacy branch must stay byte-for-byte the original, the same guarantee _old.vtl gives:
#if( $structures.isNewEditModeEnabled() ). #else and #end are each on their own line.#if. Both start at column 0. Indenting changes every legacy line.#else branch is the original, verbatim. Do not reformat it, translate its comments, fix its typos, remove its trailing spaces or change its line endings. If it has a bug, leave it; mention it in your answer if it matters.#parse and never write _new/_old files in this mode.When the original is a file on disk (you were given a path), do not retype it. Write the migrated version to a temporary file, then assemble with the shell so the legacy bytes are copied, not regenerated. This is the only reliable way to keep CRLF line endings and a missing final newline:
{ printf '#if( $structures.isNewEditModeEnabled() )\n'; cat migrated.vtl; printf '\n#else\n'; cat original.vtl; printf '\n#end'; } > result.vtl
When the content was pasted, copy the pasted legacy code into the #else exactly as the user sent it.
Velocity parses the whole file before it renders either branch. With the router, the branch not taken is never even parsed; inline, both are. So some problems that only affected the legacy editor in the three-file shape would break the new editor too. Before emitting inline, read both branches and check:
| Finding | Severity | What to do |
|---|---|---|
A #macro with the same name in both branches | Blocking | Macros are registered at parse time, and the first definition wins. That is the migrated one, so the legacy editor would silently run the new macro. Emit nothing; name the macro; offer three files. |
The legacy branch would not parse on its own: a #if/#foreach/#macro/#define without its #end, a stray #end, an #else outside an #if | Blocking | Inline would carry that parse error into the new edit mode. Emit nothing; give the line; offer three files. |
| The migrated branch would not parse on its own | Blocking | If you migrated it, that is a bug in your migration: fix it before emitting anything. If it came from the user (collapse or split), report the line like the legacy case and write nothing. |
The same variable #set in both branches | Warning | #set runs at render time and only one branch renders, so this is not a collision. Emit, but list the names in the mode line. |
Count directives the way Velocity does. Text inside ##, #* *# and #[[ ]]# is not code, and \#end is escaped. A directive name also ends at the first character that is not a letter, digit, _ or @, so $('#end-date') in a script is an #end, while #endDate is not. The full rules and examples are in reference/migration-guide.md → "Output Modes".
After a blocking finding, emit inline only if the user explicitly insists ("inline anyway"), and restate the finding in the mode line when you do.
Use this mode when the request asks for it (see the table above). Given an original file at /static/personas/keytag_custom_field.vtl, the three outputs are:
keytag_custom_field_old.vtlThe original file content, completely unchanged. Copy it verbatim — every deprecated API call, every dijit class, every dojo.ready. This is the fallback for the legacy editor.
keytag_custom_field_new.vtlThe fully migrated file with all deprecated patterns replaced per the migration rules.
keytag_custom_field.vtl (replaces the original)The conditional router — this file takes the name of the original and delegates to _new or _old based on which edit mode is active:
#if( $structures.isNewEditModeEnabled() )
#parse('/static/personas/keytag_custom_field_new.vtl')
#else
#parse('/static/personas/keytag_custom_field_old.vtl')
#end
The #parse paths must use the full server path of the file, not just the filename. Use the same directory as the original file. Indent the #parse lines with a tab and end the file right after #end, with no final newline, as the routers already in the repository do. On disk, write it with printf so no newline is added.
This pattern lets both legacy and new edit modes coexist safely — old editor users continue using the deprecated code, new editor users get the modernized version.
When the user gives you a file path, derive all three filenames automatically. In three-file mode only, if you receive file contents without a path, ask for the filename and its server path before outputting, because #parse cannot work without it.
Conversion only moves content. Never apply a migration rule to either branch while converting. It is a re-shaping, not a re-migration.
Collapse (router + _new + _old → one inline file). Read the router's two #parse paths and find the _new and _old files. The _new content goes in the #if and the _old content in the #else, using the Mode 1 layout. Run "Before emitting inline" first; the same findings apply. If the router's paths do not match the files you were given (different names or directories), say so and stop. Do not guess.
Split (one inline file → router + _new + _old). You need the router's full server path; ask for it if you do not have it.
#else: the first #else line reached while no block opened after line 1 is still open. Count block openers (#if, #foreach, #macro, #define, #literal, #@name) and #ends from line 2 on. Never just take the first #else, because branches often contain their own #if … #else … #end. The file ends with the matching #end._new.vtl is everything between the header and the top-level #else. _old.vtl is everything between that #else and the final #end. In both cases, drop the one newline the inline layout added before the #else and before the #end.#parse lines with full server paths.If the file does not start with #if( $structures.isNewEditModeEnabled() ), or has no top-level #else, it is not an inline migration. Say so; do not guess.
On disk, use the shell for both directions so bytes are copied, never retyped. Collapse is the Mode 1 command, with _new in place of migrated.vtl and _old in place of original.vtl. Split takes line ranges, where E is the line number of the top-level #else and L is the line number of the final #end:
sed -n "2,$((E-1))p" inline.vtl | perl -pe 'chomp if eof' > name_new.vtl
sed -n "$((E+1)),$((L-1))p" inline.vtl | perl -pe 'chomp if eof' > name_old.vtl
getField() calls must be inside DotCustomFieldApi.ready()DotCustomFieldApi.get() or DotCustomFieldApi.set() (the old short forms)class="dijit*") must be removed#else branch or _old.vtl) is never edited, not even its comments or whitespace$inode, $identifier, $lang, $contentlet, $structure, $field) are resolved at render time — do not confuse them with DotCustomFieldApi JavaScript APIsField reference lifecycle:
DotCustomFieldApi.ready(() => {
// Get once, reuse everywhere
const titleField = DotCustomFieldApi.getField('title');
const urlField = DotCustomFieldApi.getField('url');
// Read
const current = titleField.getValue() || '';
// Write
urlField.setValue(slugify(current));
// Watch
titleField.onChange((value) => {
urlField.setValue(slugify(value));
});
});
Field visibility and state control:
DotCustomFieldApi.ready(() => {
const mediaField = DotCustomFieldApi.getField('media');
const mediaFileField = DotCustomFieldApi.getField('mediafile');
// Show/hide based on current value
if (mediaField.getValue() === 'upload') {
mediaFileField.show();
} else {
mediaFileField.hide();
}
// React to changes
mediaField.onChange((value) => {
if (value === 'upload') {
mediaFileField.show();
} else {
mediaFileField.hide();
}
});
// Enable/disable a field
mediaFileField.disable(); // blocks editing, applies disabled styling
mediaFileField.enable(); // restores interactivity
});
Reacting to validation state (required, errors, touched):
<style>
/* Self-contained: legacy iframe pages do NOT load DaisyUI, so we ship the rule with the template. */
#slugInput.is-invalid {
border-color: #ef4444;
outline-color: #ef4444;
}
</style>
<script type="module">
DotCustomFieldApi.ready(() => {
const field = DotCustomFieldApi.getField('urlTitle');
const input = document.getElementById('slugInput');
const applyValidation = (state) => {
// Only show the error after the user (or Save) has marked the control as touched —
// mirrors how Angular's built-in fields paint the red border.
const showError = state.invalid && state.touched;
input.classList.toggle('is-invalid', showError);
};
// onValidationChange emits the initial state synchronously, so a separate
// getValidationState() call up front is redundant. The bridge auto-cleans
// on form destroy, so the unsubscribe return value can be ignored here.
field.onValidationChange(applyValidation);
});
</script>
Use a self-contained
is-invalidclass with inline<style>instead of DaisyUI'sinput-error. The legacy iframe page (legacy-custom-field.jsp) does NOT load DaisyUI or Tailwind, so aninput-errortoggle would silently produce no visual feedback there. Inside the iframe the migrated branch does not run at all:$structures.isNewEditModeEnabled()isfalsethere, because the iframe request carries nocontentTypeId, so the#else(legacy) code renders. The callback only fires in component mode (newRenderMode=component); in the legacy editor the Dojo bridge'sonValidationChangeis a no-op, and that editor has its own validation surface. See Rule 13 inreference/migration-guide.mdfor the full gotchas list.
state shape: { valid, invalid, touched, dirty, errors } (mirrors Angular's AbstractControl). errors is null when valid, otherwise a record like { required: true }.
Multiple onChange for the same field → combine into one handler:
// Old: two separate onChangeField calls for 'title'
// New: one onChange that does both
titleField.onChange((value) => {
updateURL(value);
updateFriendlyName(value);
});
Native dialog with DaisyUI modal (replaces dojoType="dijit.Dialog"):
<button type="button" id="openModalButton" class="btn btn-primary">Open modal</button>
<dialog id="myDialog" class="modal">
<div class="modal-box">
<h3 class="font-bold text-lg">Hello!</h3>
<p class="py-4">Press ESC key or click the button below to close</p>
<div class="modal-action">
<form method="dialog">
<button type="submit" class="btn">Close</button>
</form>
</div>
</div>
</dialog>
<script>
const myDialog = document.getElementById('myDialog');
const openModalButton = document.getElementById('openModalButton');
openModalButton?.addEventListener('click', () => {
myDialog?.showModal();
});
</script>
Styling (DaisyUI): Buttons → btn, btn-primary, btn-ghost, btn-sm. Inputs → input input-bordered. Selects → select select-bordered. Links → link link-primary. Use Tailwind for layout (flex, gap, w-full). Full reference in reference/migration-guide.md → “Styling with DaisyUI”.
Custom field templates can use server-side VTL variables injected by dotCMS when the field is rendered. These are resolved on the server before HTML reaches the browser — they are not available in JavaScript and must not be confused with DotCustomFieldApi.
| Variable | Type | Description |
|---|---|---|
$inode | String | The contentlet's inode (version ID) |
$identifier | String | The contentlet's persistent identifier |
$lang | long | The contentlet's language ID |
$contentlet | Contentlet | The full Contentlet object |
$structure | ContentType | The content type (structure) |
$field | Field | The current field being rendered |
Availability:
$structure and $field are always available when the custom field is rendered.$inode, $identifier, $lang, and $contentlet are populated only when editing an existing contentlet (when an inode is known). On new content, those four variables are empty/unset.Example — display context variables in the template:
<p>
<strong>inode:</strong> $inode
</p>
<p>
<strong>identifier:</strong> $identifier
</p>
<p>
<strong>lang:</strong> $lang
</p>
<p>
<strong>contentlet:</strong> $contentlet
</p>
<p>
<strong>structure:</strong> $structure
</p>
<p>
<strong>field:</strong> $field
</p>
Example — guard for new vs existing content:
#if($utilMethods.isSet($inode))
<input type="hidden" id="contentInode" value="$inode" />
#else
<p class="text-sm text-base-content/70">Save the content first to access inode-specific features.</p>
#end
For full details, availability rules, and practical examples → read reference/migration-guide.md → “Server-Side Velocity Context Variables”.
Verify the migration passes this checklist (details in reference/migration-guide.md):
Answer:
Inline output (default):
#if( $structures.isNewEditModeEnabled() ); #else and #end on their own lines#else branch is the original verbatim: not re-indented, not reformatted, comments untouched#parse added; no _new/_old files written#set variables, if any, listed in the mode lineThree-file output (on request):
_old.vtl — original file content, completely unchanged (deprecated code preserved intentionally)_new.vtl — fully migrated content#if( $structures.isNewEditModeEnabled() ) block with correct full-path #parse directives pointing to _new and _oldConversion (collapse / split):
#else, not the first oneMigrated code (the #if branch or _new.vtl):
DotCustomFieldApi.get() or .set() or .onChangeField() remainingdojo.* or dijit.* references remainingdojoType attributes remainingdijit* CSS classes remainingDotCustomFieldApi.ready()getField() calls stored in variables and reusedfield.show() / field.hide() instead of manual DOM manipulationfield.enable() / field.disable() instead of manual DOM attribute changesFor complete rules, DaisyUI styling section, all migration examples (character counter, title field, slug generator, dialogs, file browser), and edge cases → read reference/migration-guide.md.
reference/instance-migration.md (opens in a new tab)reference/migration-guide.md (opens in a new tab)scripts/tests/conftest.py (opens in a new tab)scripts/tests/test_field_body.py (opens in a new tab)scripts/tests/test_inline_problem.py (opens in a new tab)scripts/tests/test_workflow.py (opens in a new tab)scripts/vtl_migration.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
3 skills in this plugin
/dotcms-best-practicesReference for doing any single thing in dotCMS correctly — create a content type, page, template or container; place content; author VTL; wire a headless Next.js frontend; or debug a page that renders blank. Indexed by intent, so you load one file for the task at hand. Use whenever working with dotCMS content types, fields, pages, templates, containers, content placement, VTL/Velocity, the Universal Visual Editor, or a headless dotCMS frontend — and especially when a page renders empty, a slot shows "no component", or a change doesn't appear in LIVE./dotcms-create-sitesPlans and builds a complete dotCMS site in two phases. Phase 1 interviews the user and writes PLAN.md (purpose, sitemap, data model, every fact tagged) and DESIGN.md (visual identity tokens). Phase 2 hands off to the dotcms-best-practices skill, which owns the build sequence, and holds the verify-and-fix loop until every page type renders. Stops invented facts shipping as real. Supports both VTL-rendered and headless (Next.js) delivery. Use when someone wants to build, scaffold, or create a new dotCMS site or microsite.npx claudepluginhub dotcms/agent-toolkit --plugin dotcms