by Kaushal Mall

Created

February 10, 2012

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

COMMENTS

  • By Enrique Hurtarte Juarez - 4:02 PM on August 24, 2012  

    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,

    • By Kaushal Mall - 5:12 PM on August 24, 2012  

      Enrique,

      Can you please show me your code and the a screenshot of the node structure you are trying to save the nodes under.

  • By Enrique Hurtarte Juarez - 5:37 PM on August 24, 2012  

    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,

    • By Kaushal Mall - 8:17 PM on August 24, 2012  

      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 + “/”.

  • By Enrique Hurtarte Juarez - 5:57 PM on August 24, 2012  

    The node structure I shared it in the following link:

    https://docs.google.com/open?id=0B-4iiP1-RKoucW9BNXo1YWpqUms

  • By Enrique Hurtarte Juarez - 8:47 AM on August 25, 2012  

    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 %>” + “/*”;

    • By Kaushal Mall - 11:11 AM on August 27, 2012  

      Enrique,

      Can you please make sure that your news folder is of type sling:Folder or sling:OrderedFolder and try again.

  • By Enrique Hurtarte - 3:18 PM on August 27, 2012  

    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.

    • By Kaushal Mall - 4:25 PM on August 27, 2012  

      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.

  • By Enrique Hurtarte - 7:30 AM on August 28, 2012  

    Kaushal,

    Thanks for all, I’m going to find out what is the problem. Your post was very useful.

  • By Tom - 7:02 AM on November 30, 2012  

    Please add an RSS feed or email feed to your blogs.