I would like to know if it is possible to use auto-generated slugs for components. In v3 and v4 of Strapi, there were different ways to implement auto-generated slugs to collection types, the v4 tutorial can be found here: How to Create a Slug System in Strapi v4.
However, they only work for collection types. I need to use auto-generated slugs on components because the auto-generated slug of a component is supposed to be used as an anchor tag within the component. That way, users of our CMS can copy the auto-generated slug of a component and paste it into the ‘anchor’ field of another component, providing working anchor tags between components within a landing page. I have not found any way to solve this, though. Anyone got an idea?
No, landing pages are my collection types in the Content Type Builder of Strapi. A landing page can consist of multiple components. Those components should have individual ID/Slug that are generated when a user adds them to a landing page, so that their ID/Slug is used as an html id within the component and as a way to reference where to jump to when clicking on a possible other components.
Sorry for the clarification, you’re using terminology that you’ve created within Strapi so I wasn’t sure if you’re trying to jump to a component within Strapi or on an actual Landing Page. So since you’re wanting to jump to a component within Strapi, here are some thoughts:
Strapi doesn’t provide useful IDs in the Content Manager that will assist you in this case
I assume you’re going to write the jump logic yourself (link to anchors), again Strapi doesn’t do this for you
Create a button component in the sidebar to jump to where you like
If the components you’re creating are custom components, then this becomes really easy, simply use IDs from the data in the name of the IDs used in the HTML of the component
If you’re using Strapi’s predefined components, this becomes a little tricky (this is least preferred)
You could use JavaScript to look for specific HTML or text and jump to that element
Thanks for your detailed response. Regarding your points:
I am aware of that and that’s totally fine. I just need the logic to be able to reference between components within a collection type
Could you specify what you mean by using IDs from the data in the name of the IDs used in the HTML? If I were to add a dynamically generated uuid for every component within the component, that would give me a unique ID for all of them but it wouldn’t give me the possibility to view this ID within the Strapi Dashboard when viewing a collection type that includes this component because the ID would only be generated during build, which is at a later point in time than the viewing of the ‘landing page’ in Strapi.
I am trying to achieve anchors between different components within the same collection type. I use this collection type to be able to build dynamic landing pages that can be filled with the custom components I built. Every instance of this component should have a unique ID in this collection type. If I have a component, let’s call it Carousel, that I add to my landing page together with another component, let’s call it a Headline, then I want users to be able to reference the Carousel component as an anchor within the Headline component on the same page. If the Carousel therefore has an ID of carousel-1, I want users to be able to insert ‘carousel-1’ as the anchor link in the Headline component. By doing that, I can create an automatic scrolling to the desired Carousel component when for example clicking on the Heading component.
Because I re-use components not only in different collection types but also use the same component multiple times within the same collection type, constant IDs would not suffice.