Keep the MODX Forums from Eating your Back-ticks

Some tips on using back-ticks and displaying code in the MODX Forums

In the previous article, we looked at how to find bugs using a binary search. In this one, we'll look at how to keep the MODX Forums from eating your back-ticks.

MODX logo

The Problem

Suppose you post a single line of code in the MODX Forums like this:

[[getResources? &parents=`12` &tpl=`MyTpl`]]

The problem with this is that you haven't identified the code as code.

The back-ticks won't show up when the forum post is displayed. Instead, the property values will be shown with a gray background and no back-ticks, which may make your code fail when copied and pasted.

The Solution

The problem is caused by the forum software thinking that the single back-ticks are essentially code tags. The software removes the back-ticks and adds the gray background.

Luckily, there are two ways to identify code that you want to display as pre-formatted text in the forums. One method is to add three back-ticks above and below the line like this:

[[getResources? &parents=`12` &tpl=`MyTpl`]]

The other method is to leave out the three back-ticks before and after the code, and simply add four spaces in front of each line of the code like this:

    [[getResources? &parents=`12` &tpl=`MyTpl`]]

When you do that, the back-ticks in your code will be taken literally and will display as they should and the format of the code will be maintained. The forum software removes the four leading spaces from each line before displaying it to help keep the code from going too far to the right.

You might wonder what will happen if you use both methods together. The answer is that the back-ticks will look right, but all the code will be indented by four extra spaces, which may push some of the code off the right side of the page.


There is a good discussion of some of the finer points of using back-ticks in the MODX forums here.

Coming Up

In the next article, we'll look at some reasons why your TV values are not showing up when using getResources or pdoResources.

For more information on how to use MODX to create a web site, see my web site Bob's Guides, or better yet, buy my book: MODX: The Official Guide.

Looking for high-quality, MODX-friendly hosting? As of May 2016, Bob's Guides is hosted at A2 hosting. (More information in the box below.)

Comments (0)

Please login to comment.