Craft 3マルチサイトは非常に便利です。しかし、私は、エントリを編集中にリストのドロップダウンがわかりました。
私はいくつかのサイトグループを持っていて、それぞれはサイトバージョンのローカライズ版を含んでいます:
- International Sales
- English version
- Production
- English version
- French version
— Distribution
- English version
- French version
craft.app.sites.getAllSites()
を使用して)各サイトをループするときに適切な表示名を得るために、このようなサイトグループを設定することができました:
- International Sales
- International Sales
- Production
- Production
- Production
— Distribution
- French Distribution
- Distribution France
しかし、CPのドロップダウンからサイトを編集するときに、どのサイトバージョンがどのロケールを使用しているかをユーザーに知らせるものはほとんどありません。
だから私はこのような名前でそれぞれの名前を変更しなければならなかった:
- International Sales
- International Sales → English
- Production
- Production → English
- Production → French
— Distribution
- Distribution France → English
- Distribution France → French
今私は2つの問題に直面しています:
-
Twigを使用してすべてのサイトの順序付きリストを設定するにはどうすればよいですか? なぜなら
craft.app.sites.getAllSites()
は、 アルファベット順。たとえば、私は
Production グループの前に表示される Distribution グループ -
サイト名とは異なる表示名を設定するにはどうすればよいですか?なぜなら
国際営業→英語、制作→英語などは醜い名前です。私はしたいと思います
リストの2番目のバージョンのように名前を表示する: フランス語流通などの国際販売
If you would use a custom plugin you can create this function in
your (I know it’s deprecated but I don’t know a better name)
PluginVariable
public function createSiteQuery(): Query
{
return (new Query())
->select(['id', 'groupId', 'name', 'handle', 'language', 'primary', 'hasUrls', 'baseUrl', 'sortOrder'])
->from(['{{%sites}}']);
}
次に、
{% set sites = craft.plugin-handle.createSiteQuery().orderby({'whatever': 'you want'}).all() %}
そして、あなたが好きなだけ多くのパラメータをクエリに添付してください…特定の言語でサイトを取得したい場合は、
{% set sites = craft.plugin-handle.createSiteQuery().where('language = "en"').all() %}
あなたは Yii2クエリークラスの力を完全に持っています。サイトを好きなようにグループ化し、順序を変更することができます。単一の
SiteRecord
または複数の SiteRecords
クラス参照を使用して、フロントエンドに好きな情報を表示できます。
You are free to change the site names in your frontend with a
static array map in your PHP code as well.
Create a map with siteHandle => "new display name"
and do something like
{{ craft.plugin-handle.displayCustomSiteName(site.handle) }}