Add ID in Widget Properties

Amy Kurtz asked on December 12, 2014 19:58

I've created an editable text widget and added it in my page's widget zone. To configure it, the only option I see in the Widget Properties is Widget Container. Is there a way to also add a unique ID to the individual widget instance as well? The purpose is to anchor to that widget on the page.

Correct Answer

Amy Kurtz answered on January 7, 2015 16:12

Since we needed an unlimited amount of unique ID's on a page, we enabled the Anchor button in the WYSIWYG editor so that users could drop in an anchor to that section. With CSS we were able to position them at the top.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Vilém Jeniš answered on December 14, 2014 08:31 (last edited on December 10, 2019 02:30)

Yes there is. There are several options however. You can either add a property to the web part on which you widget is based or use an existing property. Then you'll need to go to the widget's configuration and make the field visible in the configuration form.

Let's say I've decided to use the Web part title property for my purpose. This is a system property and thus I'll go to the widget configuration > system properties Screenshot and enable the field for configuration. However this doesn't make the ID necessarily unique. To ensure the uniqueness I'd suggest providing your own value by a Macro. You could generate a GUID or have something more sensible like {%CurrentUser.UserName + "_" + CurrentDocument.AliasPath |(identity)GlobalAdministrator%} or along these lines. Given you'll only have one of those per document per user it is unique enough.

Let me know if that helps.

Vilém

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.