In my particular case I need to be able to switch the layout that the template extends. Is this possible to do using locales?
Untested, but should be fairly straightforward.
{% if craft.locale == 'de' %}
{% set template = '_layout_de.html' %}
{% else %}
{% set template = '_layout.html' %}
{% endif %}
{% extends template %}
or
{% extends craft.locale == 'de' ? '_layout_de.html' : '_layout.html' %}
or using a locale folder (thank josh baker)
{% extends craft.locale ~ '/_layout' %}
-
2You might also use string concatenation, which makes adding new layouts easier in future. For example
{% extends craft.locale ~ '/_layout' %}
would point to/templates/en/_layout
. – Joshua Baker Jul 22 '15 at 17:40 -
-
When I try that I get a "Multiple extends tags are forbidden" message returned. Something to do with the processing order perhaps where it's evaluating
extends
before the conditional construct? – Ian Jul 27 '15 at 11:14 -
1Most likely just doesn't like the multiple extends statements. I modified the example using a single extends and variables. Also, did you try one of the other methods? – Douglas McDonald Jul 27 '15 at 15:33
-
The error message gave it away. :) In my case your other suggestion wouldn't fit my particular use case as it could be one of several and not just one or the other. I didn't notice Josh's suggestion though but it was the kind of pseudo logic I had in my head without quite knowing how to apply it. I've given it a try though and successfully got it to work along (with a slight tweak for my particular template folder structure:
{% extends "layouts/" ~ craft.locale ~ '/layout-name' %}
. Many thanks for the help and suggestions. – Ian Jul 28 '15 at 15:37