Content Fragment Multifield with a tagfield? | Community
Skip to main content
Level 2
March 21, 2024
Solved

Content Fragment Multifield with a tagfield?

  • March 21, 2024
  • 1 reply
  • 756 views

Hi all - How do I create a content fragment that has a multifield with a tagfield accomodating multiple tags?  I'm using this example to create multifields with textfields only, but am unable to get a multifield to work with a textfield and tagfield. When I try to author the multifield with text, and multiple tags, it saves the text and the first tag only.  Thanks!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Raja_Reddy

Hi @a74048191r 

To create a content fragment with a multifield that includes a tagfield, you will need to modify the XML of the content fragment model.

<?xml version="1.0" encoding="UTF-8"?> <jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" jcr:primaryType="nt:unstructured" sling:resourceType="core/wcm/components/contentfragment/v1/contentfragment"> <modelPath jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container" name="./modelPath" fieldLabel="Model Path" fieldDescription="Select the model path for this content fragment." required="{Boolean}true"> <items jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/pathbrowser" rootPath="/content/dam/cfm-models" name="items" predicate="nosystem" forceSelection="{Boolean}true" allowBlank="{Boolean}false" showVersionInfo="{Boolean}true" fieldLabel="Model Path" fieldDescription="Select the model path for this content fragment." value=""/> </modelPath> <elements jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container" name="./elements" fieldLabel="Elements" fieldDescription="Add elements to this content fragment."> <multifield jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container" name="./multifield" fieldLabel="Multifield" fieldDescription="Add multiple elements to this content fragment."> <field jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container" name="./field" fieldLabel="Field" fieldDescription="Add a field to this element."> <items jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/textfield" name="items" fieldLabel="Text" fieldDescription="Enter text for this field." value=""/> </field> <field jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container" name="./tags" fieldLabel="Tags" fieldDescription="Add tags to this element."> <items jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/tagfield" name="items" fieldLabel="Tags" fieldDescription="Enter tags for this field." value=""/> </field> </multifield> </elements> </jcr:root>

This XML includes a multifield with two fields: one for text and one for tags. The tagfield is defined using the `granite/ui/components/coral/foundation/form/tagfield` resource type.

Once you have updated the XML, you can create a new content fragment using this model and test it.

1 reply

Raja_Reddy
Community Advisor
Raja_ReddyCommunity AdvisorAccepted solution
Community Advisor
March 22, 2024

Hi @a74048191r 

To create a content fragment with a multifield that includes a tagfield, you will need to modify the XML of the content fragment model.

<?xml version="1.0" encoding="UTF-8"?> <jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" jcr:primaryType="nt:unstructured" sling:resourceType="core/wcm/components/contentfragment/v1/contentfragment"> <modelPath jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container" name="./modelPath" fieldLabel="Model Path" fieldDescription="Select the model path for this content fragment." required="{Boolean}true"> <items jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/pathbrowser" rootPath="/content/dam/cfm-models" name="items" predicate="nosystem" forceSelection="{Boolean}true" allowBlank="{Boolean}false" showVersionInfo="{Boolean}true" fieldLabel="Model Path" fieldDescription="Select the model path for this content fragment." value=""/> </modelPath> <elements jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container" name="./elements" fieldLabel="Elements" fieldDescription="Add elements to this content fragment."> <multifield jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container" name="./multifield" fieldLabel="Multifield" fieldDescription="Add multiple elements to this content fragment."> <field jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container" name="./field" fieldLabel="Field" fieldDescription="Add a field to this element."> <items jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/textfield" name="items" fieldLabel="Text" fieldDescription="Enter text for this field." value=""/> </field> <field jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container" name="./tags" fieldLabel="Tags" fieldDescription="Add tags to this element."> <items jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/tagfield" name="items" fieldLabel="Tags" fieldDescription="Enter tags for this field." value=""/> </field> </multifield> </elements> </jcr:root>

This XML includes a multifield with two fields: one for text and one for tags. The tagfield is defined using the `granite/ui/components/coral/foundation/form/tagfield` resource type.

Once you have updated the XML, you can create a new content fragment using this model and test it.