Expand my Community achievements bar.

SOLVED

Content Fragment Multifield with a tagfield?

Avatar

Level 2

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!

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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.



View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

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.