primarySite Twig global variable #16370
-
|
Similar to the currentSite variable, but returning the primarySite model instead. My reason for suggesting, if I wanted to use the primary site properties e.g. base URL in another site, I currently would need to do a query with craft.app.sites, or use the siteUrl function but the params are little awkward e.g. to get the homepage of the primary site A syntax of: Would be cleaner. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
|
You can get the primary site via @jamesmacwhite That {{ siteUrl(siteId=1) }}Or, if you want to avoid hard coding the ID: {{ siteUrl(siteId=craft.app.sites.primarySite.id) }}It would be cool to be able to do things like this though: {{ siteUrl('login', siteId=primarySite.id) }} |
Beta Was this translation helpful? Give feedback.
-
|
@mmikkel Thanks! I've learnt something new with named arguments today with Twig, to make siteUrl usage a bit cleaner for sure! |
Beta Was this translation helpful? Give feedback.
-
|
Added for Craft 4.14 and 5.6! (92cdb09) |
Beta Was this translation helpful? Give feedback.
Added for Craft 4.14 and 5.6! (92cdb09)