Hi Experts,
New in AEM.
I have to customize page title textfield at page properties using jcr:title (Title) string by appending some fixed string every time. Have to programmatically achieve this before saving the page properties to JCR.
I am thinking to do this using JS, by assigning the pagetitle value before "SimpleSave" or "Save & Close" action is called.
Where I can make this change if my approach is correct ? I am unable to find the location or there is any better way of doing that ?
Please reply.
@kautuk_sahni @BrianKasingli @arunpatidar
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @shya,
For your use-case, you can leverage Event handling functionality in AEM. We have multiple ways to do it and I will discuss one of the ways.
For more info on the event listeners please visit my blog here.
Hope this helps.
Thanks,
Kiran Vedantam.
If the String that you want to append is fixed, then better append it in your rendering script rather than doing it from front end(Javascript).
I need to save that pagetitle with jcr:title + some fixed string under page properties in JCR once use clicks on save action button at page properties page.. Use will not provide this propery value, user will only enter title, other descriptions of the page. So how I can do that at rendering script, some guidance please ?
Views
Replies
Total Likes
you can do it in your sling model and show it in HTL.
why do you need to save this in jcr ? (i.e if it is only display purpose)
@ValueMapValue(name = "jcr:title")
private String titleText;
public String getTitleText() {
return titleText+"YourString";
}
Hi @shya,
For your use-case, you can leverage Event handling functionality in AEM. We have multiple ways to do it and I will discuss one of the ways.
For more info on the event listeners please visit my blog here.
Hope this helps.
Thanks,
Kiran Vedantam.
Views
Replies
Total Likes
@shya how are you planning to use this information, is this for SEO? you can easily do this with sightly:
<head>
<title>${pageProperties['jcr:title']} | My Company Name</title>
</head>
I thought of doing the same, but I have to preserve this value in JCR and some other servlet is referring the value to send page properties node json to other systems.
Views
Replies
Total Likes
Hi @shya
One approach is that you can always control the value of the fields in the page properties by using a simple js like the one below
(function (document, $, Granite) {
"use strict";
$(document).on("click", ".granite-form-saveactivator", function (e) {
saveCustomTitle(e)
});
$(document).on("click", ".foundation-wizard-control", function(e) {
if($(this)[0].innerText=='Create'){
saveCustomTitle(e)
}
})
})(document, Granite.$, Granite);
function saveCustomTitle(e){
e.stopPropagation();
e.preventDefault();
let titleEl = $("input[name='./jcr:title']");
titleEl.val(titleEl.val() + " custom text");
e.target.dispatchEvent(new MouseEvent('click', e.nativeEvent));
}
The js file should be added to an appropriate clientlib folder so that it gets loaded while rendering the page properties dialog.
Hi, we had the same requirement to add a prefix to the title, we added a new field in the page property and read it when we created <title> tag, since this property always be available in JCR and you can reuse it, you can customize it as well. you can add default value as well to this new property to get autofill value on creating.
Hi @shya,
Your approach is correct. Create a clientlib with OOTB categories as "cq.authoring.dialog" (and dependencies as "cq.jquery") as it is needed only in author.
In the JS logic, amend the title conditionally (that is only if it doesn't contains the fixed string, otherwise for every submit of page properties dialog, title value will be amended with fixed string)