Table of contents
This is going to be a quick and informative article, so let’s dive straight in 🏄♂️
Prerequisites
- Laravel Valet
- A Craft CMS project
- And some basic knowledge of the two
The part where I tell you how it’s done
For this article I’m using a fresh Craft installation using this url: maindomain.test.
These are the steps I took for creating the bare essentials to test some multi-site, multi-domain sweetness:
- In Craft create a new site using these details:
- From your terminal cd into your project folder
- Enter command valet link otherdomain
Now navigate to otherdomain.test in your browser and you will see the Craft welcome screen. But how do we see which site we are querying?
How to see which site we are querying
- In your code editor go into your index.twig
- Place the following code inside
<!-- Inside of the div with the class "content" -->
<ul>
<li>Site ID: {{ currentSite.id }}</li>
<li>Site Handle: {{ currentSite.handle }}</li>
<li>Site Name: {{ currentSite.name }}</li>
<li>Site Language: {{ currentSite.language }}</li>
<li>Is Primary Site?: {{ currentSite.primary }}</li>
<li>Base URL: {{ currentSite.baseUrl }}</li>
</ul>
- Refresh your browser
- Switch between maindomain.test and otherdomain.test
- You’ll see different details 🎉
Now you’re able to test your multi-site + multi-domain setup locally.
Now build something awesome! 🚀
Got any questions or suggestions for a better approach?
Let me know! @daaf730