4

We are building a multilingual site.

We have different domains and slugs for German and English pages/sections i.e. projects is called projekte...

Right now the template used is called "projects.html" which we want to use for all languages, but Craft is looking for each slug's language template and not the English one?

Do we need to duplicate each template or?

Thanks in advance.

  • Can you clarify, do you want the url to be localized (/projects for english, /projekte for german), or not? And are you hitting the template directly, or is it used by one of your sections? – André Elvan Sep 8 '14 at 10:41
  • hey im using projekte/ and projects/ as slug...but my template is called _projects.html...and for the german section.... a 404 is brought up...(because there isnt a _projekte.html)...i just want 1 template to be used for all languages – nexflo Sep 8 '14 at 11:34
4

You can create new template files for your second locale and simply use Twig include to only maintain one template for all of your locales.

projekte.html:

{% include 'projects.html' %}

Use a locale specific subfolder (craft/templates/de/) to separate the german templates from your main / first locale templates (see the Template Localization article in the Docs on how this works).

Another way to handle localized URIs is to not use "URI to template matching" (pt. 6 in the Routing article) but configure an entry that loads your template instead (pt. 4).

Create a single section with "projects.html" for the template that should get loaded if the single's URL is requested. The template's filename is irrelevant for the URI matching and you can set the entry's slug to whatever you want in both of your locales.

Before creating many single sections now, also consider using a "Pages" structure section instead.

| improve this answer | |
0

I changed the /page/_entry to:

                {% include ["pages/_#{subpage.type}", "pages/_#{subpage.slug}.html", "pages/_#{subpage.id}.html", 'pages/_default.html'] with {entry: subpage} %}

This way it first uses the page type, then the slug, then the id and at last the default page.

This allows for easy localized templating with using the same templates.

Thanx @carls

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.