[PAGES-488] More versatile url property in template definition Created: 24/Aug/21  Updated: 02/Nov/21  Resolved: 05/Oct/21

Status: Closed
Project: Magnolia pages module
Component/s: None
Affects Version/s: None
Fix Version/s: 6.2.12

Type: Task Priority: Neutral
Reporter: Robert Šiška Assignee: Canh Nguyen
Resolution: Done Votes: 0
Labels: VN-Implementation
Remaining Estimate: Not Specified
Time Spent: 3d 7h
Original Estimate: Not Specified

Issue Links:
Problem/Incident
causes PAGES-522 External SPA: Iframe url, language sw... Closed
dependency
is depended upon by MGNLPN-587 CLONE - Preview as visitor is not wor... Closed
is depended upon by PAGES-499 Preview as visitor is not working wit... Closed
is depended upon by MGNLFE-88 Support for Next.js Closed
documentation
to be documented by PAGES-516 DOC: url property in template definition Closed
Template:
Acceptance criteria:
Empty
Task DoR:
Empty
Documentation update required:
Yes
Date of First Response:
Epic Link: External SPA
Sprint: HL & LD 37, HL & LD 38
Story Points: 3

 Description   

The external page editor sets the external SPA URL to the iframe. When the iframe is loaded, the SPA will get href from the iframe window to get necessary params to fetch data from the REST endpoint. There's a problem that multiple pages can have a same page definition but each page needs different path/params to initialize.

To support multiple pages with a same page definition and each page has different URL, we should support the url property in template definition as url template like:

The params to be added to the URL could be the node's properties and some extra params when the page editor is in edit mode/preview mode.



 Comments   
Comment by Mikaël Geljić [ 30/Aug/21 ]
  • Could make sense to conventionally rename "url" in template-def to "baseUrl" and just append the path (minus root-page path), as a default strategy, and without placeholder necessary (could let define more elaborate strategies later as we learn more from the use cases);
  • Other legit point: most template defs in the same project are likely talking to the same baseUrl, so we could extract a default in project/global config.
Comment by Christopher Zimmermann [ 21/Sep/21 ]

canh.nguyen which parameters are supported now - is it as suggested in description or how?

Comment by Canh Nguyen [ 21/Sep/21 ]

czimmermann currently, it supports all page node attributes, included custom attributes that we add to the node. Nested attributes are not supported yet.

Comment by Christopher Zimmermann [ 05/Oct/21 ]

canh.nguyen Can you update description with how it actually works now?

Comment by Canh Nguyen [ 05/Oct/21 ]

The definition has three new properties:

  • baseUrl:
    http://foo.bar/someContext
  • routeTemplate:
    {{path}}?aParam={paramName}
  • spaRouterClass: Optional. I will use the default SPA router if we don't set it.

The value will be encoded, but the param inside `{{ }}` will not be encoded. All node's attributes are supported. In case developers want to support more params, they need to implement SpaRouter.

Pages editor will resolve routeTemplate and join baseUrl and resolved routeTemplate into complete URL

Update: Each implementation of SpaRouter is expected to have a constructor that has SpaRenderableDefinition param

Comment by Christopher Zimmermann [ 11/Oct/21 ]

canh.nguyen How exactly do I use spaRouterClass, can you provide an example?

Comment by Canh Nguyen [ 11/Oct/21 ]

czimmermann it's like:

spaRouterClass: info.magnolia.pages.spa.routing.DefaultSpaRouter

We need to register an implementation of SpaRouter class in case we have a custom one.

Comment by Christopher Zimmermann [ 12/Oct/21 ]

FYI I got errors with

routeTemplate: {{path}}

But this worked: 

routeTemplate: '{{@path}}'

cc: mdrapela

Generated at Mon Feb 12 06:19:26 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.