Saturday, 27 July 2019

Hide facet item in Adobe Seach and Promote

Using Adobe Search and Promote we can able to hide specific facet items. For example, you have a product type as "Lorem Ipsum" and you want to hide this facet item under "Product Type" facet, you can achieve this by adding a business rule. After adding this rule, "Lorem Ipsum" facet item is not displayed.

Rules -> Business Rule




After adding this rule test it in simular or in author AEM instance.


Click here to see how to integrate AEM and SnP.

Tuesday, 23 July 2019

Redirect to specific page using Adobe Search and Promote

Using Adobe Search and Promote we can redirect a user to a specific page skipping the search results page.

Consider a scenario for eCommerce website, if a user searches for a product id then it's good to redirect the user to product display page instead of the search results page. We can achieve this by adding a post search rule in SnP as shown below.

Rules -> Post Search Rule


After adding this rule test it in simular or in author AEM instance.


Click here to see how to integrate AEM and SnP.

Search each word in query param using Adobe Search and Promote

We can use Adobe Search and Promote to search each word and display the search results. By default, SnP will search whole string in Query param. For example, if your search query is "AEM Quickstart" then your search results will be *AEM Quickstart*. You won't see results with only "AEM" or "Quickstart".

To achieve this, we should add Post Search Rules.

Rules -> Post Search Rule -> +Add Rule


After adding this rule test it in simular or in author AEM instance.

Click here to see how to integrate AEM and SnP.

Sunday, 14 July 2019

Publish AEM Content to Salesforce Communities using CMS Connect

Salesforce has come up with a feature to connect the third-party Content management systems with Salesforce communities. You can connect CMS components, HTML, JSON, CSS, and JavaScript to customize your community and keep its branding consistent with your website. CMS connect feature renders content dynamically from CMS systems.


CMS Connect supports content from different CMS systems like AEM, Sitecore, Drupal, SDL, WordPress and Other.


Let's see how to pull content from AEM to Salesforce community.

Enable CORS in AEM

From AEM 6.3, Adobe added Cross-Origin Resource Sharing Policy (CORS) as OSGi configuration. CORS configurations can be added as an OSGi config factories.

CORS configurations are managed as OSGi configuration factories in AEM, with each policy being represented as one instance of the factory.
  • Navigate to http://localhost:4502/system/console/configMgr
  • Search for Adobe Granite Cross Origin Resource Sharing Policy (com.adobe.granite.cors.impl.CORSPolicyImpl)
Click here to check how to enable CORS for older AEM versions (<6.3)

Monday, 8 July 2019

Nested Multifield (coral 3) with Sling Model in AEM

Create AEM multi module project using archtype 11
Create a new component with cq:dialog for Touch UI as shown below.


<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
    jcr:primaryType="nt:unstructured"
    jcr:title="Country Details"
    sling:resourceType="cq/gui/components/authoring/dialog">
    <content
        jcr:primaryType="nt:unstructured"
        sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">
        <items jcr:primaryType="nt:unstructured">
            <column
                jcr:primaryType="nt:unstructured"
                sling:resourceType="granite/ui/components/coral/foundation/container">
                <items jcr:primaryType="nt:unstructured">
                    <countries
                        jcr:primaryType="nt:unstructured"
                        sling:resourceType="granite/ui/components/coral/foundation/form/multifield"
                        composite="{Boolean}true"
                        fieldLabel="Countries">
                        <field
                            jcr:primaryType="nt:unstructured"
                            sling:resourceType="granite/ui/components/coral/foundation/container"
                            name="./countries">
                            <items jcr:primaryType="nt:unstructured">
                                <column
                                    jcr:primaryType="nt:unstructured"
                                    sling:resourceType="granite/ui/components/coral/foundation/container">
                                    <items jcr:primaryType="nt:unstructured">
                                        <countryName
                                            jcr:primaryType="nt:unstructured"
                                            sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
                                            fieldLabel="Country Name"
                                            name="./countryName"/>                                        
                                        <states
                                            jcr:primaryType="nt:unstructured"
                                            sling:resourceType="granite/ui/components/coral/foundation/form/multifield"
                                            composite="{Boolean}true"
                                            fieldLabel="States">
                                            <field
                                                jcr:primaryType="nt:unstructured"
                                                sling:resourceType="granite/ui/components/coral/foundation/container"
                                                name="./states">
                                                <items jcr:primaryType="nt:unstructured">
                                                    <column
                                                        jcr:primaryType="nt:unstructured"
                                                        sling:resourceType="granite/ui/components/coral/foundation/container">
                                                        <items jcr:primaryType="nt:unstructured">
                                                            <stateName
                                                                jcr:primaryType="nt:unstructured"
                                                                sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
                                                                fieldLabel="State Name"
                                                                name="./stateName"/>
                                                            <statePostal
                                                                jcr:primaryType="nt:unstructured"
                                                                sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
                                                                fieldLabel="State Postal"
                                                                name="./statePostal"/>
                                                            <statePopulation
                                                                jcr:primaryType="nt:unstructured"
                                                                sling:resourceType="granite/ui/components/coral/foundation/form/numberfield"
                                                                fieldLabel="State Population"
                                                                name="./statePopulation"/>
                                                            <stateDensity
                                                                jcr:primaryType="nt:unstructured"
                                                                sling:resourceType="granite/ui/components/coral/foundation/form/select"
                                                                fieldDescription="Select State Density"
                                                                fieldLabel="State Density"
                                                                name="./stateDensity">
                                                                <items jcr:primaryType="nt:unstructured">
                                                                    <high
                                                                        jcr:primaryType="nt:unstructured"
                                                                        text="High"
                                                                        value="high"/>
                                                                    <medium
                                                                        jcr:primaryType="nt:unstructured"
                                                                        text="Medium"
                                                                        value="medium"/>
                                                                    <low
                                                                        jcr:primaryType="nt:unstructured"
                                                                        text="Low"
                                                                        value="low"/>                                                                    
                                                                </items>
                                                            </stateDensity>
                                                        </items>
                                                    </column>
                                                </items>
                                            </field>
                                        </states>
                                    </items>
                                </column>
                            </items>
                        </field>
                    </countries>
                </items>
            </column>
        </items>
    </content>
</jcr:root>



Now create slingmodels to get the authored values.
  1. CountriesModel.java
  2. Country.java
  3. State.java

Tuesday, 2 July 2019

Avoid encoding dispatcher URLs

Rewrite rules on Apache web server that attempt to redirect to URLs with special characters such as & or ? or #anchor aren't being redirected properly.  For example:
RewriteRule ^/we-retail.html /we-retail.html#anchor [R=301,L]

To avoid encoding the # character, add the NE flag to the rewrite rules:
RewriteRule ^/test.html /test.html#anchor [NE,R=301,L]

Special characters such as & and ?, will be converted to their hexcode equivalent. Using the [NE] flag prevents that from happening.
RewriteRule ^/anchor/(.+) /bigpage.html#$1 [NE,R]

The above example will redirect /anchor/xyz to /bigpage.html#xyz. Omitting the [NE] will result in the # being converted to its hexcode equivalent, %23, which will then result in a 404 Not Found error condition.
Reference: RewriteRule Flags

Remove .html extension at dispatcher

Add below dispatcher configurations in dispatcher.any file to remove .html extension from the URL.
#Enable RewriteEngine

RewriteEngine on


#Map the root folder to the home page

RewriteRule ^/?$ /content/we-retail/us/en/home.html [PT,L]


# remove any trailing slash, if it's there.

RewriteRule ^(.+)/$ $1


#Remove .html Extension

RewriteRule ^(.*).html$ $1 [R,L]


#Shorten the URL

RewriteRule ^/content/we-retail/us/(.*)$ $1 [R,L]


#Remove .html and map products url

RewriteRule ^/en/products.html/(.*)$ /en/products/$1 [R,L]


RewriteCond %{REQUEST_URI} !^/(apps|content|etc|home|libs|system|tmp|var|services)

RewriteRule ^/en/products/(.*)$ /content/we-retail/us/en/products.html/$1 [PT,L]


RewriteCond %{REQUEST_URI} !^/(apps|content|etc|home|libs|system|tmp|var|services)

RewriteRule ^/(.*)$ /content/we-retail/us/$1.html [PT,L]