0

When I create a language string with multiple HTML elements Joomla! automatically inserts \n between them.

This shows up as a literal \n in the string.

Does anyone know why and how to overcome this issue?

I insert

<h2>This is a heading</h2>
<p>This is some body text</p>

I see

<h2>This is a heading</h2>
\n
<p>This is some body text</p>
\n

If I add the \n then I see \\n in the output

  • 1
    Can you clarify whether it's /n or \n? – Sharky Jan 11 at 17:14
  • Good point, yes it's \n I have updated the question – Eoin Jan 11 at 17:41
  • 1
    A major suggestion, don't put HTML in language string if you can help it. Only place I do is my extension description. Other than that, all HTML derives from layouts – Lodder Jan 11 at 18:37
  • I see, ok good idea, I'll just create loads of PHPs and each paragraph as a language string. Thanks. – Eoin Jan 11 at 19:25
2

This is expected. Language strings must not contain line breaks. Having them would cause invalid INI files. This is not a valid language file:

COM_EXAMPLE_MY_STRING="<h2>This is a heading</h2>
<p>This is some body text</p>"

This is valid:

COM_EXAMPLE_MY_STRING="<h2>This is a heading</h2>\n<p>This is some body text</p>"

Thanks to @lodder for this suggestion

Instead of using HTML in the language string, try creating multiple language strings. Then call each language string independently and use PHP to surround the string with the HTML element you want.

  • Ok fine, I can add \n without getting too upset. How do I stop it showing in the output? In the output I get \\n. Double slash. – Eoin Jan 11 at 18:19

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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