I have four domains – domain.com, domain.org, domain.africa and domain.net. All share the same user base from db and some content. Users can register and log in on any website. Works perfectly. The problem is each website has its own registration and login form, which means when something changes I have to edit each form for each website as they must all work with the same db.
What I am trying to achieve is to have one registration and one login form shared by all four domains. I have done that and its working, but I am struggling to load what is specific to each domain, depending on which domain the user is currently on – like the header and footer for that domain.
I am using php with twig (no framework) and have tried various ways to achieve what I want, mostly found online, but none seems to work. I am willing to use twig inside javascript, if necessary.
Tried twig inside javascript (if url contains):
<script type="text/javascript"> var siteName=document.URL; </script>
<script>
if (siteName.indexOf("domain1") != -1)
{document.write("include('domains/domain1/includes/header.html')" )}
else if (siteName.indexOf("domain2") != -1)
{document.write("include('domains/domain2/includes/header.html')")}
else if (siteName.indexOf("domain3") != -1)
{document.write("include('domains/domain3/includes/header.html')")}
else if (siteName.indexOf("domain4") != -1)
{document.write("include('domains/domain4/includes/header.html')")}
</script>
The above only loads domain1 header for all domains.
Using twig only:
{% if 'domain1' in url %}
{{ include('domains/domain1/includes/header.html') }}
{% endif %}
AND
{% if url == "https://domain.africa" %}
{% include('domain/location/includes/site.header.html') %}
{% endif %}
Twig gets no result.
In javascript method when I add a string like “domain1” and “domain2”, etc for each domain, instead of the twig include function, I get the correct output for each domain I visit. But the moment I add the twig include function the headers, I get the domain1 header loaded for all domains