Search code examples
modelosgislingsightlyaem-6

Is there a way to generate a unique resource name in AEM?


I've created a table with a list inside tbody. It will generate a number of rows. However, I have to make the resource name unique every row. Any ideas on this?

    <table>
            <thead>
                <tr>
                    <td></td>
                </tr>
            </thead>
            <tbody data-sly-list="${itemCount}">
                <tr>
                    <td>
                        <div data-sly-resource="${'resourceName' @ resourceType='components/content/mycomponent'}"></div>
                    </td>
                </tr>
            </tbody>
        </table>

Solution

  • Not sure I get what you plan to do there. It seems you want to generated unique synthetic resource names.

    For that you could use itemList.count or itemList.index to have values such as: res1, res2 ... or res0, res1 ... See details in the HTL specification.

    You would probably have to use data-sly-set to concatenate the number to the text:

            <tbody data-sly-list="${itemCount}">
                <tr>
                    <td data-sly-set.resourceName="res${itemList.count}">
                        <div data-sly-resource="${resourceName @ resourceType='components/content/mycomponent'}"></div>
                    </td>
                </tr>
            </tbody>