Level 1
Level 2
Melden Sie sich an, um alle Badges zu sehen
Hello Team,
I have an rte field in my Content Fragment models.(Note: Which is present in many CF models).
I want to call some custom js file whenever I open the CF. So, below article worked for me.
So, whenver I create a CF from a CF model, my custom logic is execture.
Now, my query is I want to execute this logic from say: 10 CF models out of my 20 CF models (where rte field is present). How can I restirct my custom logic? Note: Custom js categories has: dam.cfm.authoring.v2, companyName.rte
cc @arunpatidar @BrianKasingli @giuseppebag @SantoshSai @HrishikeshKagne
Thanks in advance
Zugriffe
Antworten
Likes gesamt
You can find the model associated with multi-field and restrict execution of logic based on model. The JS will be loaded for all the model but your code will be executing only when field matches the model.
Hi @Mahesh_Gunaje,
You could do this in 2 ways:
1. Check the active CF model path before running your JS
When a Content Fragment opens in the editor, AEM passes the model path in the page’s URL or in the editor’s internal data.
You can use that to conditionally execute your script.
(function(document, $) {
"use strict";
// Execute only when CF authoring is active
$(document).on("cf-editor-loaded", function() {
try {
// Retrieve model path (AEM adds it as `model` param in URL)
const params = new URLSearchParams(window.location.search);
const modelPath = params.get("model");
// e.g. /conf/company/settings/dam/cfm/models/article
// Allowed models list
const allowedModels = [
"/conf/company/settings/dam/cfm/models/modelA",
"/conf/company/settings/dam/cfm/models/modelB",
"/conf/company/settings/dam/cfm/models/modelC"
];
// Run only if the current CF model is in the allowed list
if (allowedModels.includes(modelPath)) {
console.log("Running custom logic for allowed CF model:", modelPath);
runCustomRTELogic();
} else {
console.log("CF model not in allowed list:", modelPath);
}
} catch (e) {
console.error("Error reading model path:", e);
}
});
function runCustomRTELogic() {
// Your custom JS logic goes here
alert("Custom logic triggered for this CF model!");
}
})(document, Granite.$);
Here: cf-editor-loaded is a common safe hook if you’re using AEM 6.5’s CF Editor.
If you use the OOTB category (dam.cfm.authoring.v2) + your custom clientlib (companyName.rte), ensure your clientlib includes a dependency on it, not vice versa.
You can also check via Granite.author.ContentFragmentEditor.getModelPath() in newer versions.
2. Conditional load via extraClientlibs in model editor (AEM 6.5+)
If you have only a few specific CF models, you can assign a custom clientlib per model directly in CRXDE:
Path:
/conf/<project>/settings/dam/cfm/models/<modelname>/jcr:content
Add property:
Name: extraClientlibs
Type: String[]
Value: [ "companyName.rte" ]
That way, your JS runs only when editing those models.
No need for runtime filtering.
Zugriffe
Antworten
Likes gesamt
Zugriffe
Likes
Antworten