I have been investigating why the following
doesn’t output the correct content when used in a ditto template. YAMS works with Ditto by replacing placeholders with a special yams-select construct that includes multiple-language versions of the content from which the correct language will be selected later. When PHx is used too, like in the above example, Ditto will first request the content of the placeholder from the YAMS ditto extender - which will return the yams-select construct - and then Ditto will apply PHx rules to the output. In the example above the rule involves truncating the output - which destroys the integrity of the yams-select construct resulting in broken yams code appearing in the output.
The only not-very-elegant workaround that I have for this particular case is as follows: Write out a yams-select construct explicitly, letting ditto apply phx to the actual placeholders. For a website with English (en), Spanish (es) and Russian (ru) the appropriate construct would be:
(yams-select:9999[+id+])(lang:9999[+id+]:en)[+content_en:limit=`300`+](lang:9999[+id+]:es)[+content_es:limit=`300`+](lang:9999[+id+]:ru)[+content_ru:limit=`300`+](/yams-select:9999[+id+])
This construct assumes that all the documents in the ditto output are multilingual.
Normally I’d advise against using YAMS constructs explicitly. Instead its best to use a YAMS snippet call - which will automatically adjust the constructs when new languages are added and knows how which documents are multi- and mono- lingual. However, it’s not possible to do that inside a ditto template in a way which will work with PHx unfortunately.
I’ve got some ideas for how this workaround might be avoided in future, in a way which would tie in with some changes designed to improve efficiency by avoiding the need for the 1000s of mysql queries currently required to grab multilingual content when using lots of large ditto and wayfinder calls.