Skip to content

Instantly share code, notes, and snippets.

@saulovenancio
Forked from nateyolles/.content.xml
Created February 16, 2018 17:46
Show Gist options
  • Save saulovenancio/93adadd10f8be40377295b765ff06664 to your computer and use it in GitHub Desktop.
Save saulovenancio/93adadd10f8be40377295b765ff06664 to your computer and use it in GitHub Desktop.
AEM using Granite Render Conditions
<items jcr:primaryType="nt:unstructured">
<widgetAlways
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldLabel="This always shows"
name="./widgetAlways"/>
<widgetHeaderChrome
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldLabel="This only shows when header &quot;User-Agent&quot; contains &quot;chrome&quot;"
name="./widgetHeaderChrome">
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${granite:containsIgnoreCase(header['User-Agent'], 'chrome')}"/>
</widgetHeaderChrome>
<widgetHeaderFirefox
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldLabel="This only shows when header &quot;User-Agent&quot; contains &quot;firefox&quot;"
name="./widgetHeaderFirefox">
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${granite:containsIgnoreCase(header['User-Agent'], 'firefox')}"/>
</widgetHeaderFirefox>
<widgetHeaderOther
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldLabel="This only shows when header &quot;User-Agent&quot; does not contain &quot;chrome&quot; or &quot;firefox&quot;"
name="./widgetHeaderOther">
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${!granite:containsIgnoreCase(header['User-Agent'], 'chrome') and !granite:containsIgnoreCase(header['User-Agent'], 'firefox')}"/>
</widgetHeaderOther>
<widgetSuffix
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldLabel="This only shows with suffix &quot;/foo/bar&quot;"
name="./widgetSuffix">
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${granite:containsIgnoreCase(requestPathInfo.suffix, '/foo/bar')}"/>
</widgetSuffix>
<widgetSelector
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/select"
fieldLabel="This only shows with selector &quot;bar&quot;"
name="./widgetSelector">
<items jcr:primaryType="nt:unstructured">
<alpha
jcr:primaryType="nt:unstructured"
text="alpha"
value="alpha"/>
<bravo
jcr:primaryType="nt:unstructured"
text="bravo"
value="bravo"/>
</items>
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${requestPathInfo.selectorString == 'bar'}"/>
</widgetSelector>
<widgetSelectorNotEmpty
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldLabel="This shows with any selector string"
name="./widgetSelectorNotEmpty">
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${not empty requestPathInfo.selectorString}"/>
</widgetSelectorNotEmpty>
<widgetParam
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldLabel="This only shows with querystring param &quot;biz=baz&quot;"
name="./widgetParam">
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${param.biz == 'baz'}"/>
</widgetParam>
<widgetCookie
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldLabel="This only shows with cookie &quot;bat=qux&quot;"
name="./widgetCookie">
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${cookie.bat.value == 'qux'}"/>
</widgetCookie>
<widgetPrivilege
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldLabel="This only shows if you can write to &quot;/etc/workflow/instances&quot;"
name="./widgetPrivilege">
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/privilege"
path="/etc/workflow/instances"
privileges="jcr:write"/>
</widgetPrivilege>
<widgetNotLockedCanModfy
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldLabel="This only shows when the suffix is not locked and can be modified"
name="./widgetNotLockedCanModfy">
<rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/renderconditions/and">
<not
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/renderconditions/not">
<islocked
jcr:primaryType="nt:unstructured"
sling:resourceType="cq/gui/components/renderconditions/islocked"
path="${requestPathInfo.suffix}"/>
</not>
<canmodify
jcr:primaryType="nt:unstructured"
sling:resourceType="cq/gui/components/renderconditions/canmodify"
path="${requestPathInfo.suffix}"/>
</rendercondition>
</widgetNotLockedCanModfy>
<widgetCustomRenderConditionWeekend
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldLabel="This only shows on weekends"
name="./widgetCustomRenderConditionWeekend">
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="renderconditiondemo/components/renderconditions/day"
days="[Sunday,Saturday]"/>
</widgetCustomRenderConditionWeekend>
<widgetCustomRenderConditionWeekday
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldLabel="This only shows on weekdays"
name="./widgetCustomRenderConditionWeekday">
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="renderconditiondemo/components/renderconditions/day"
days="[Monday,Tuesday,Wednesday,Thursday,Friday]"/>
</widgetCustomRenderConditionWeekday>
<widgetCustomRenderConditionHasProperty
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldLabel="This only shows if &quot;/content/renderconditiondemo/en/jcr:content/par/text&quot; has property &quot;text&quot;"
name="./widgetCustomRenderConditionHasProperty">
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="renderconditiondemo/components/renderconditions/hasProperty"
resourcePath="${requestPathInfo.suffix}"
propertyName="text"/>
</widgetCustomRenderConditionHasProperty>
</items>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment