Though Localised XF say for header and footer, work fine with sling dynamic include on author and publisher, it doesn’t work properly on dispatcher. However with few small changes we can make this work for Localised XF’s as well. Lets see how.
Firstly Why Localised XF with SDI works both on author and publish but not on dispatcher?
If XF is configured on the template for multilingual sites using MSM then the OOTB XF product code will deliver the localised XF for that site. However the code fails in case of SDI.
OOTB code expects current page as content page and not the template page(in case of SDI) and hence the code breaks in case of SDI and it is not able to deliver localized XF’s on the dispatcher.
If I use SDI, the “currentPage” points to the template page (in case of “/conf”) on dispatcher while the XF code expects the /content… actual page?
In author or publish, you will always get “currentPage” as the actual current page(ie. /content/myproject/us/en). But in dispatcher, you will get the currentPage based on the SDI request path (“/conf” or “/content/experience-fragments/”).
And Yes, you might need currentPage for multiple purposes like, getting page properties or getting to know the current site or brand, and so on. The solution is to pass the current page path as a suffix to the SDI request using mod_rewrite in dispatcher.
2. Overlay and Modify the OOTB XF code to read the current page from suffix.
Please note All Sling models used for components on header/footer XF would also need to be modified similarly to read current page from suffix.