craft.request.firstSegment
と
craft.request.lastSegment
は動作しますが、
craft.request.secondSegment
は動作しません。任意のURLセグメントの値を取得する方法はありますか(ExpressionEngineなど)?
ベストアンサー
同じセグメント配列の位置でセグメントが常にではないの場合、さらに一貫性のある別の方法があります。
routes.php ファイルの特定のマスクと一致するようにルートを設定します。
return [
'' => ['template' => 'team']
];
そして、あなたの小枝のテンプレートで、URLにこれらの2つが提供されていれば、
country_code
と section_URI
変数にアクセスすることができます。定義されていないことを確認することもできます。
{% if country_code is defined %}
//Do something with country_code
{% endif %}
Note: The syntax used in Craft 3 routing
differs from the one in Craft 2: https://github.com/craftcms/docs/blob/master/en/upgrade.md#url-rules