5

I am totally new to Sitecore, and a front-end developer, so please bear with me.

I'm on a project that is prototyped using JSS and for some of our components we'd like to define custom types like: "align" that would be one of ["top", "middle", "bottom"] but the allowed, predefined, types (as in SingleLineText or RichText for examples) are limited.

Is there a way to define such lists as "types"?

Also, is it possible to define custom types like type: { some, other, fields } and later reuse those as { name: "foo", type: "MyCustomType" } ?

I've checked the JSS documentation but so far it's pretty unclear if this is possible; any pointers is good.

1 Answer 1

5

In Sitecore such a list would be implemented via a droplink field (in JSS manifest this is referred to as ContentLink).

Essentially you'd make a folder in data/content to store your list items, such as /data/content/alignments/{top|middle|bottom}/en.yml. Give each of those an id, i.e. id:align-top.

Then on your component instance (on a route) where you'd like to refer to an alignment, add a ContentLink field, and set the value to an ID reference to the alignment item's ID:

myAlignmentField:
    id: align-top
3
  • Amazing! Thanks a lot. If I get it correctly, ContentLink is actually "a link to data/content". How do you actually point, refer, to the list? I see that you create alignments in data/content, you refer in a route with "myAlignmentField"… but I don't see how you actually say that "this alignment list is taking values from the alignments directory" Let say I define the component like this: { name: "alignments", type: ContentLink } How do I link alignments to this so the contributor have a list of some fields to choose from?
    – kaneel
    Commented Nov 3, 2018 at 10:54
  • 1
    The source of the content link can be set in the manifest as well using the source attribute to specify the Sitecore path to retrieve items to list.
    – Kam Figy
    Commented Nov 5, 2018 at 20:13
  • ok will fiddle with that, thanks a lot again!
    – kaneel
    Commented Nov 6, 2018 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.