Search

I’m currently working on a bilingual site which is using the Typography with Markdown text formatter. My site has two textareas - one for the primary language and another for the secondary language (German or English). Which language is the primary depends on context of the content so I have another field that lets me set the primary language. So far, so easy.

Now I’d like to apply German typography to my German texts and English typography to my English texts: Is there a way for a text formatter to determine the value of an other field in the same section before processing the text? Does a text formatter know anything about the section’s context at all?

You can’t do this directly with the formatter — it doesn’t know about the entry itself. A text formatter is applied inside the __applyFormatting method of the Textarea class.

Maybe you could use the EntryPreEdit delegate. You can get the values from the POST array to determine which language is being used. Since the Entry object has been instantiated at this point, you should be able to iterate over its Field objects and change the formatter such as:

$field->set('formatter', 'formatter_name_here');

So when the field comes to apply the formatter the ->get('formatter') call inside __applyFormatting should get the formatter you’ve just temporarily set.

Thanks, Nick. That sounds like a neat solution.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details