18 Replies Latest reply on Jul 11, 2013 9:47 AM by NitroHazeDev

    Inserting fragments in CQ AEM 5.6

    NitroHazeDev Level 1

      Hello all,

       

      Is there a way to retrieve a fragment from apache docroot and place it in CQ,

      probably header as a fragment to be inserted to my site developed in CQ5.6

       

      Regards,

      NZ

        • 1. Re: Inserting fragments in CQ AEM 5.6
          msulliva Level 2

          I assume you're using the Dispatcher in Apache.  Apache Server-Side Includes SSI [1] are comments and don't show unless the SSI processor is present and work fine with the Dispatcher.  I've detected the WCMMode and in Edit Mode on Author will use a CQ equivalent include of a header and on the Publisher these would output the SSI comment tags and get included by apache.

           

          There is also Sling Dynamic Include [2], that might make this easier, but I haven't used this yet.

           

          [1] http://httpd.apache.org/docs/2.2/howto/ssi.html

          [2] http://www.cognifide.com/blogs/cq/sling-dynamic-include/

          • 2. Re: Inserting fragments in CQ AEM 5.6
            NitroHazeDev Level 1

            Thanks a ton for help, will check and revert back

            Thanks again

             

            Regards,

            • 3. Re: Inserting fragments in CQ AEM 5.6
              NitroHazeDev Level 1

              Hello,

               

              Is there a documentation on SSI with AEM/CQ?

              • 4. Re: Inserting fragments in CQ AEM 5.6
                msulliva Level 2

                Do you have any specific questions?

                 

                I don't think they have any official documentation on it since it is an Apache thing.

                 

                This is what my config looks like in the main <Directory> tag to enable SSI on all html, but I would imagine this does add some overrhead to each request, but I use SSI on all of my pages so it's necessary.

                 

                I have mod include loaded and my config is below http://httpd.apache.org/docs/current/mod/mod_include.html:

                 

                 

                <IfModule disp_apache2.c>   

                    SetHandler dispatcher-handler

                </IfModule>

                 

                Options +IncludesNoExec

                AllowOverride None

                 

                AddOutputFilterByType INCLUDES text/html

                • 5. Re: Inserting fragments in CQ AEM 5.6
                  NitroHazeDev Level 1

                  Thanks again, Yeah, i was wondering if this would help me include html, header / footer  stored elsewhere, at some http://www.abc.com/.../footer.html in my jsp?

                  • 6. Re: Inserting fragments in CQ AEM 5.6
                    msulliva Level 2

                    If by stored elsewhere you mean stored somewhere in the Apache docroot, then yes.  If you want to load the HTML from another server Iyou could probably do that with just a Regular CQ component in combination with an HTTPClient Request.

                     

                    This is what the SSI tag looks like:

                     

                    <!--#include virtual="/footer.html" -->

                     

                    This would pull in the contents on of the docroot/footer.html file wherever this was placed in your JSP.  This wouldn't show up on the Author or Publish, and you would need to do some WCMMode detection to accomplish that.

                     

                    Can you provide more information about where this http://www.abc.com/.../footer.html lives and what generates it?

                    • 7. Re: Inserting fragments in CQ AEM 5.6
                      NitroHazeDev Level 1

                      Yes, it would have to be picked up from Apache docroot.Appreciate your kind help, and since I am new to this, so may raise couple of dumb questions,kindly assist me,

                      where exactly would i have to add  below lines?

                       

                      Also are these sufficient along with <!--#include virtual="/footer.html" --> in the jsp?

                       

                      <IfModule disp_apache2.c>  

                          SetHandler dispatcher-handler

                      </IfModule>

                       

                      Options +IncludesNoExec

                      AllowOverride None

                       

                      AddOutputFilterByType INCLUDES text/html

                       

                      Are there any other settings/configurations that i have to set? assuming i start from scratch.

                       

                      Regards,

                      • 8. Re: Inserting fragments in CQ AEM 5.6
                        msulliva Level 2

                        As far as I know the SSI Comment tag would need the docroot relative path to your header or footer file, and you would put that comment tag in a JSP somewhere.

                         

                        Then in the Dispatcher Apache Conf, near the section mentioned in [1], you would make the Directory section where the SetHandler is look more like what I posted, with the Options +IncludesNoExec and then the AddOutputFilter.  You would also need to make sure the mod_include module is loaded where other modules are loaded `LoadModule include_module    modules/mod_include.so`

                         

                        [1] http://dev.day.com/docs/en/cq/current/deploying/dispatcher/disp_install.html#par_69_47_000 9

                        • 9. Re: Inserting fragments in CQ AEM 5.6
                          NitroHazeDev Level 1

                          Well after long struggle, I was able to set up apache and dispatcher locally for the author instance and i was able to enable SSI in apache, so when i hit http://localhost/index.html, it evaluated the code <!--#echo var="DATE_LOCAL" --> and now when i install SDI , and try to hit geometrixx home page via dispatcher with             <!--#include virtual="/index.html" --> in the jsp , it doesn't fetch the date time for me!...

                           

                          Please help.

                           

                          Regards,

                          • 10. Re: Inserting fragments in CQ AEM 5.6
                            msulliva Level 2

                            Can you show any relevant sections of your Apache conf where you have added the SSI config

                             

                            Also can you explain a little about the layout of your directory structure on the dispatcher such as:

                             

                            docroot/

                                index.html

                                content/

                                    geometrixx/

                                         en.html

                             

                            Can you see the SSI tags in the source of the Geometrixx page?

                            • 11. Re: Inserting fragments in CQ AEM 5.6
                              NitroHazeDev Level 1

                              Sure, I could .

                               

                              I have pasted portion of httpd.conf file below, the lines i have modified.

                               

                              My index.html is placed under c:/Users/XXX/Website/index.html. This index.html echo's the date time   <!--#echo var="DATE_LOCAL" -->

                               

                              Under apps/geometrixx/components/homepage/content.jsp, i have added the following line,        

                                 <!--#include virtual="/index.html" --> and this is what appears in the page source on geometrixx home page.

                               

                               

                               

                              I have built the SDI OSGI bundle and successfully installed it. The configuration for the filter is as below.

                               

                              Please let me know if anything is missing

                               

                              httpd.confDynamicIncludeFilter.PNG

                              ************

                              LoadModule dispatcher_module modules/disp_apache2.2.dll

                              <IfModule dispatcher_module>

                                DispatcherConfig conf/author_dispatcher_new.any

                                DispatcherLog    logs/dispatcher.log

                                DispatcherLogLevel 3

                                DispatcherNoServerHeader 0

                                DispatcherDeclineRoot 0

                                DispatcherUseProcessedURL 0

                                DispatcherPassError 0

                              </IfModule>

                               

                               

                              <Directory />

                                <IfModule dispatcher_module>

                                  SetHandler dispatcher-handler

                                </IfModule>

                               

                               

                                Options +Includes

                                AllowOverride None

                                AddType text/html .html

                                AddOutputFilterByType INCLUDES .html

                              </Directory>

                              LoadModule actions_module modules/mod_actions.so

                              LoadModule alias_module modules/mod_alias.so

                              LoadModule asis_module modules/mod_asis.so

                              LoadModule auth_basic_module modules/mod_auth_basic.so

                              .

                              .

                               

                              DocumentRoot "c:/Users/XXX/Website"

                               

                               

                              <Directory "c:/Users/XXX/Website/">

                                  #

                                  # Possible values for the Options directive are "None", "All",

                                  # or any combination of:

                                  #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

                                  #

                                  # Note that "MultiViews" must be named *explicitly* --- "Options All"

                                  # doesn't give it to you.

                                  #

                                  # The Options directive is both complicated and important.  Please see

                                  # http://httpd.apache.org/docs/2.2/mod/core.html#options

                                  # for more information.

                                  #

                                 

                                        Options Indexes FollowSymLinks MultiViews Includes

                                 

                                  #

                                  # AllowOverride controls what directives may be placed in .htaccess files.

                                  # It can be "All", "None", or any combination of the keywords:

                                  #   Options FileInfo AuthConfig Limit

                                  #

                                  AllowOverride None

                               

                               

                                  #

                                  # Controls who can get stuff from this server.

                                  #

                                  Order allow,deny

                                  Allow from all

                                        AddType text/html .html

                                  AddOutputFilter INCLUDES .html

                               

                               

                              </Directory>

                               

                               

                              <Directory "c:/Users/XXX/Softwares/Apache/Apache2/cgi-bin">

                                  AllowOverride None

                                  Options None

                                  Order allow,deny

                                  Allow from all

                              </Directory>

                              • 12. Re: Inserting fragments in CQ AEM 5.6
                                msulliva Level 2

                                My Bad, I may have missed a detail, <!--#include virtual will actually make a call back through Apache, so /index.html will actually make a request back through the dispatcher through to the Author, which is obviously not desired in this case, but in the case of SDI, exactly what is desired.

                                 

                                But first, I wanted to clear something up, Sling Dynamic Includes is a solution that utilizes Server Side Includes and Ajax, but is initated on the Author / Publish instance.  Its primary purpose is to facilitate mixed static (cached on dispatcher) and Dynamic content on the same page, and simplifys this by just wrapping around the typical component include style in Sling.  So you include a component a semi normal way and the components listed in the filters in the OSGI config that you found will outside of the Authoring environment, be converted into SSI or Ajax.  So when those are cached by a dispatcher they remain dynamic, their exampls is the "Hello John", without SSI once the Dispatcher caches the homepage with "Hello John" when Jan Logs in she will see the Cached page, "Hello John".  With SDI Jane will see "Hello Jane" while the rest of the page remains static and cached.

                                 

                                So with that said, this doesn't sound like your use case, you simply want to use SSI to include a file dynamically from the Apache Server DocRoot, not the AEM/CQ Author or Publisher as SDI would facilitate.  I also want to re-itterate that SSI runs only in Apache and happens on top of the Dispatcher Handler, so the Author and Publish instances should just be spitting out the Comment tags, on the Dipather, Apache will dynamically include the SII file.

                                 

                                So, using your setup, I'm concerned that you were able to pull up your SSI file at http://localhost/index.html because the Dispathcher should pick that up and request /index.html from your Author instance, which will likely result in being redirected to the login page, or the /projects.html (assuming 5.6+).

                                 

                                So to me that indicates that your Dispatcher isn't properly forwarding to the Author or Publish Instance.  I would recommend moving your Dispatcher Related Changes Below the existing DocRoot statement and <Directory "c:/Users/XXX/Website/"> tag.  You have your override above, which may allow the default Apache Conf to replace any of your settings.

                                 

                                As for my oversight, the Dispatcher will see the SSI request and forward that to the Author / Publisher, so to prevent that, you can define a directory to disable the Dispatcher AFTER the other directories are defined, and store your include in there.  I chose "includes" so that would look like:

                                  

                                 

                                ## Other Apache Directory stuff here ##

                                 

                                ## Your Dispatcher Conf here ##

                                 

                                <Directory "c:/Users/XXX/Website/includes">

                                    SetHandler None

                                </Directory>

                                 

                                  

                                So in addition, to help troubleshoot, make sure you put your include tag in the /apps/geometrixx/components/homepage/content.jsp and I would recommend wrapping this in a non-SSI thing to verify your change is there but not working.

                                 

                                 

                                <div id="main">

                                    <h1>From Author</h1>

                                    <!--#include virtual="/includes/index.html" -->

                                    <h1>From Author</h1>

                                    <div class="container_16">

                                 

                                 

                                And I would do similar in your index.html on the Apache docroot/includes/index.html

                                 

                                 

                                <h1>From Dispatcher</h1>

                                <!--#echo var="DATE_LOCAL" -->

                                <h1>From Dispatcher</h1>

                                • 13. Re: Inserting fragments in CQ AEM 5.6
                                  NitroHazeDev Level 1

                                  So, in our case there would be stuff coming in, eg. the header saying "Welcome John", and this would be dynamic, along with that, we would have the top nav section being picked up from the apache docroot, and the footer ofcourse, since the contents in the footer would not be present in CQ, eg. links in footer section.

                                   

                                  After reading your post i felt that SDI was helpful given the scenario.

                                  Now when i said localhost:80/index.html, and it displayed the current date time, it was without the loadModule section below, ie.  without dispatcher configurations.

                                  And when i hit localhost:80 with the below LoadModule configuration for the dispatcher, it shoots up the projects.html page as you mentioned.

                                   

                                  Now i tried having the index.html under includes folder and referenced it, in my content.jsp, but in vain. Is there any virtual host configuration that i am missing. And probably if you could give me an id of yours, i could send the conf file and the necessary files to you.

                                   

                                  I followed your advice of having the H1 tags and when i clicked on http://localhost/content/geometrixx/en.html?cq_ck=1373403211747 i see the below snapshot but can't see the dispatcher include from index.html file

                                   

                                  Again thanks a ton for your patience and help.

                                   

                                  Capture.PNG

                                  httpd.conf:

                                   

                                  # Example:

                                  # LoadModule foo_module modules/mod_foo.so

                                  #

                                   

                                   

                                  LoadModule dispatcher_module modules/disp_apache2.2.dll

                                  <IfModule disp_apache2.c>

                                    DispatcherConfig conf/author_dispatcher_new.any

                                    DispatcherLog    logs/dispatcher.log

                                    DispatcherLogLevel 3

                                    DispatcherNoServerHeader 0

                                    DispatcherDeclineRoot 0

                                    DispatcherUseProcessedURL 0

                                    DispatcherPassError 0

                                  </IfModule>

                                   

                                   

                                  <Directory />

                                    <IfModule disp_apache2.c>

                                      SetHandler dispatcher-handler

                                    </IfModule>

                                   

                                   

                                    Options +Includes

                                    AllowOverride None

                                    AddType text/html .html

                                    AddOutputFilterByType INCLUDES .html

                                  </Directory>

                                   

                                   

                                   

                                  Regards,

                                  NZ

                                  • 14. Re: Inserting fragments in CQ AEM 5.6
                                    msulliva Level 2

                                    When you view the page source of http://localhost/content/geometrixx/en.html does it have the SSI Comment Tag still nested between the H1 tags?

                                     

                                    Also, try this in your directory:

                                     

                                    AddOutputFilter INCLUDES .html

                                     

                                    # OR

                                     

                                    AddOutputFilterByType INCLUDES text/html

                                     

                                     

                                    I don't think AddOutputFilterByType will match an extension such as .html but a MIME type such "text/html" as you've shown.

                                    • 15. Re: Inserting fragments in CQ AEM 5.6
                                      NitroHazeDev Level 1

                                      I have also modified a line in author_dispatcher.any as below, pointing to webserver docroot.

                                       

                                      /cache

                                            {

                                            # The docroot must be equal to the document root of the webserver. The

                                            # dispatcher will store files relative to this directory and subsequent

                                            # requests may be "declined" by the dispatcher, allowing the webserver

                                            # to deliver them just like static files.     

                                       

                                       

                                            /docroot "c:/Users/XXX/Website/includes"

                                       

                                            # Sets the level upto which files named ".stat" will be created in the

                                            # document root of the webserver. When an activation request for some

                                            # page is received, only files within the same subtree are affected

                                            # by the invalidation.

                                            /statfileslevel  "0"

                                      • 16. Re: Inserting fragments in CQ AEM 5.6
                                        msulliva Level 2

                                        I don't think this is desired, that should be your docroot or some location where it will Cache files from the Author / Publisher, not the includes directory where you would store the SSI headers and footers.

                                         

                                        The point of the includes directory was to disable the dispatcher for just that directory, and that would be the location where you would reference the files for SSI.

                                        • 17. Re: Inserting fragments in CQ AEM 5.6
                                          msulliva Level 2

                                          Can you post your full copies of each of these files to a public Dropbox or Github Gist or any other method but here and just post back a link:

                                           

                                          docroot/includes/index.html (or whatever you're trying to include)

                                          http.conf

                                          author_dispatcher.any

                                          • 18. Re: Inserting fragments in CQ AEM 5.6
                                            NitroHazeDev Level 1

                                            Hello,

                                            Thanks a ton for the help,

                                            I was able to solve the issue using Apache SSI, tweaks in httpd.conf. But now am trying to make it work using SDI, created a footer component and included the comment tag in the jsp, and included the footer component using cq:include, but unsure if this is a right way to go ahead with.

                                             

                                            But guess got it working thanks a ton:) appreciate ur help and suggestions

                                             

                                            Regards