magnolia

Links to custom content type in Magnolia CMS


I created a custom content type for events and I can list the active events in a page with their summary. I want to create a details page for every event, currently the generated link for every event points to the event name as if it is a separate page. How can I have a page called view-event that will capture the event name and display its content

<ul>
    [#assign events = cmsfn.contentByPath("/", "events") ]
    [#list cmsfn.children(events, "ev:event") as event ]
        [#assign active = event.isActive!false]
            [#if active]
                <li>${event.name} - <a href="${cmsfn.link(event)}">details</a></li>
            [/#if]
    [/#list]
</ul>

Solution

  • I don't think it works that way. If you want to link to a page showing the event, you have to have create such page. You can then pass the event that page should show via either selector or as virtual subpage or via request parameter. See for example how in travel demo tours or destinations are shown. It's the same concept.

    In Travel demo, content lives in custom type (tour or destination respectively). However if you open pages app, you will see that under /travel website, there's one page for tours (/travel/tour) and one for destinations (/travel/destination). In the demo, selectors are used to pass info about what tour or destination you want to display. You can see that by observing the top level navigation and see that it points to /travel/tour~active~.html, where the part between ~ is the selector that page template of tour page then uses to resolve concrete piece of content to show.

    You could build the same using virtual subpages and virtual uri mapping, but in the end there needs to be a page template and associated page that understands the info you are passing in and how to render the custom content type. Passing just link to the custom content type item will not render the page.

    Alternatively, if you develop SPA, you can also request custom content type over delivery endpoint and get it in form of JSON, but then it's your SPA that is responsible for rendering that JSON as html for the browser to present to the user.

    In the element that you have pasted in your question, you can list all the events and their details directly. But if you want to point to the details of the event via hyperlink as you are trying to do and have that page to show the content you need to create the page and the template. For example, create page called /view-event in your website tree. Create template called view-event and assign it to the page. Then change the snippet above in your event-overview page to link to the view-event to look like <a href="/view-event~${event.name}~">details</a>. That way you get event name (or id or what you need) passed to the view-event page and be able to retrieve it there via state.selector and with that have view-event page render what is needed. More on that in Magnolia Documentation