문제

I'm building a multilingual website with ModX, so I installed the Babel extra and the things seem to be working fine.

I am now wondering how to handle my templates and I can't come up with a solution for using the same template for pages with different languages (would be ideal, no code duplication).

Indeed, consider this code in my template that lists posts in the sidebar:

   <h3>Archives</h3>
   <ul>
     [[!Archivist? &target=`7` &parents=`3,4`]]
   </ul>

target=7 and parents=3,4 refer to Resources in English, so I obviously cannot use this code in my template for Resources in Chinese. The only workaround I could think of is to have different templates for each language. Is this the right way to go?

도움이 되었습니까?

해결책

You can create system settings in the language contexts. [click on the context in the resource tree & go to settings.] You can then use these just like system settings:

[[!Archivist? &target=`[[++system_setting_1]]` &parents=`[[++system_setting_2]]`]]

As for the

Archives

- you can use lexicon settings for those or detect the context:

[[*context_key:is=`French`:then=`Archiv`:else=`Archives`]]

다른 팁

This is exactly what lexicons are for. Read the docs here: http://rtfm.modx.com/revolution/2.x/developing-in-modx/advanced-development/internationalization

Add the lexicons you need, in each language, then implement in your template as follows:

<h3>[[%archives? 
      &topic=`mytopic` 
      &namespace=`mynamespace` 
      &language=`[[++cultureKey]]`
      ]]
</h3>

<ul>
  [[!Archivist? &target=`7` &parents=`3,4`]]
</ul>

Sean's suggestion above regarding Context Settings is the correct way to feed in context-specific parameters for your snippets.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top