chris
November 28, 2024, 9:02am
#1
I am using 2 site definitions, french and english.
some data are accessible across the 2 sites.
sometimes, i need to generate an url from one site (english) toward the other site (french)
I look into the page twig filter but didnt find anything here.
I am guessing i’d need to generate the url in php using the pagename and attributes, but how to handle the choice of the site here ?
daft
January 10, 2025, 4:47am
#2
The sitePicker should be able to generate links to other sites. If you provide an example, perhaps we can show you the way…
chris
January 10, 2025, 10:09am
#3
thanks @daft ,
I managed to find a solution to that requirement, i cant remember how though haha
chris
January 21, 2025, 7:07pm
#4
I actually didnt find a proper solution.
my use case is the following.
The website offer two locales, english and thai.
on the user account, therefore after login, a page will display the courses he is enrolled in.
These courses can be coming from the site English or the Thai one.
the account page is using the scope ->withoutGlobalScopes()
to retrieve all the courses he is enrolled in whatever the side he is currently on.
then I set the url for each course, like in the component blogPosts
from the RainLab.Blog
plugin with the following code
$courses->each(function ($course) {
$course->setUrl($this->previewPage, $this->controller, []);
});
and obviously, the url generated should be related to the course related site and not the current site.
Does it make sense ?
thanks for any help
chris
January 21, 2025, 7:37pm
#5
I have found this solution in case of anyone needs it as well some day:
$page = Page::loadCached($this->getTheme(), $this->previewPage);
$course->url = Cms::siteUrl($page, $site, ['course' => $course->slug]);