The out of the box scaffolding lets you choose a target path which where all the pages you create using the scaffolding will be stored.
I recently ran into a use case where the client wanted to save the pages to a dynamic path based on the date on which the page was created. One can achieve the fore mentioned use case by doing something similar to what I will lay out in this blog post.
1. Override the out of the box wcm/scaffolding path by creating the same path structure in the apps folder. The new structure should look like below.
You can copy the contents of the folder in the apps directory from the libs directory.
2. We will have to update the wcm/scaffolding/components/scaffolding/body.jsp file to add our custom code to change the save location.
- Make sure the following classes are imported.
- The code to get the current date
- In the myForm.addButton method, update the out of the box code to change the formUrl to your dynamic value. Code below.
That should be it! You are now saving pages created using a scaffolding in dynamic locations






Hi Kaushal,
I tried your solution, but I didn’t work this code lines in my tests.
//Custom Code
if (!isUpdate ) {
if ( ) {
var site = frm.findField(“./jcr:content/contentpar/articleBody/site”).getValue();
var formUrl = “” + “/” + site + “/” + “” + “/” + “”
+ “/” + “” + “/*”;
} else {
var site = frm.findField(“./jcr:content/contentpar/articleBody/site”).getValue();
var formUrl = “” + “/” + site + “/” + “” + “/” + “”
+ “/” + “” + “/*”;
}
frm.url = formUrl;
}//End Custom Code
I adapted this code for my test, but I’m receiving the following error:
*ERROR* [127.0.0.1 [1345765762162] POST /content/geometrixx/en/company/news/08/22/2012/* HTTP/1.1] org.apache.sling.servlets.post.impl.operations.ModifyOperation Exception during response processing. javax.jcr.nodetype.ConstraintViolationException: No child node definition for 22 found in node /content/geometrixx/en/company/news/08
Can you explain in more detail how to implement your solution? or any comments?
Thanks in advance,
Enrique,
Can you please show me your code and the a screenshot of the node structure you are trying to save the nodes under.
In the top of the body.jsp, I added the following code as you indicate:
//Custom Code
Calendar today = Calendar.getInstance();
int year = today.get( Calendar.YEAR );
int month = today.get( Calendar.MONTH ) + 1;
int day = today.get( Calendar.DAY_OF_MONTH );
Next, I added the following code to form the URL (not a big deal),
//Custom Code
if( !isUpdate ) {
frm.url = “” +”/” + “” + “/” + “” + “/” + “” + “/*”;
}//End Custom Code
Thanks for your help,
why does your form url have a bunch of “/”. If you are going to use the current date, your form url should be something like this.
../ + site + “/” + currentDate + “/” + currentYear + “/”.
The node structure I shared it in the following link:
https://docs.google.com/open?id=0B-4iiP1-RKoucW9BNXo1YWpqUms
Sorry, but when I wrote the code in the text area field, the variables were lost. The original line was:
frm.url = “<%= contentPath %>” +”/” + “<%= year %>” + “/” + “<%= month %>” + “/” + “<%= day %>” + “/*”;
Enrique,
Can you please make sure that your news folder is of type sling:Folder or sling:OrderedFolder and try again.
Kaushai,
All right! Now, the code is working with sling:OrderedFolder node type but why not it could work below the /content/geometrixx/en/company/news/ path (NEWS node is cq:Page node type) . What is the difference? By other hand, CSS was lost in the new generated article.
Please, can you explain me? I’m lost in this point.
Enrique,
I will have to look at your implementation to figure out why the CSS isnt rendering correctly, its not something I can tell you how to fix without looking at it. As for it not working for a cq:Page, I would recommend googling that error. That should give you more information.
Kaushal,
Thanks for all, I’m going to find out what is the problem. Your post was very useful.
Please add an RSS feed or email feed to your blogs.
Tom,
You can access the feeds on the blogs using any of the URL’s explained on the URL below.
http://codex.wordpress.org/WordPress_Feeds
http://example.com/?feed=rss
http://example.com/?feed=rss2
http://example.com/?feed=rdf
http://example.com/?feed=atom