Displaying line breaks/ in dynamic data tag output?

Hi! I am using dynamic data tags to render data from my plugin’s settings page on the front end (stuff like business phone number, address).

I am using a multiline textarea box for office hours; data like this:

Mondays to Thursdays: 9:00am–4:00pm
Fridays: 9:00am—1:00pm
Saturdays: Closed

I’m doing some debug.log logging in the ci_render_dynamic_content() function to see what is coming out.

Here is the resulting debug.log output for my textarea field:

Mondays to Thursdays: 9:00am\u20134:00pm\r\nFridays: 9:00am\u20141:00pm\r\nSaturdays: Closed

I tried adding the nl2br function to my code but that didn’t seem to help, i.e.:

// Attempt to add line breaks to textarea output:
function ci_render_dynamic_data($tag, $post, $context = 'text') {
    // Fetch all stored data from the 'ci_data' option
    $ci_data = get_option('ci_data');

    // Check if the tag matches any of the expected dynamic tags
    foreach (ci_get_dynamic_tags() as $key => $label) {
        if ($tag === "{ci_{$key}}") {
            if ($key === 'church_office_hours' && isset($ci_data[$key])) {
                // Apply nl2br() to 'church_office_hours' to convert newlines to <br> tags
                return nl2br(esc_html($ci_data[$key]));
            } elseif (isset($ci_data[$key])) {
                return esc_html($ci_data[$key]);
            } else {
                return 'N/A';
            }
        }
    }

    return $tag; // Return tag unchanged if not matched
}

On the page it’s rendering like this:

(tried both a Basic Text and an HTML element)

Is there a way I can preserve the line breaks in the Bricks output?

Thanks!

What about using CSS?

< span class=“hours–item” >Mondays to Thursdays: 9:00am–4:00pm< /span >
< span class=“hours–item” >Fridays: 9:00am—1:00pm< /span >
< span class=“hours–item” >Saturdays: Closed< /span >

.hours–item {display: block;}

1 Like

Thanks Pete!

This wasn’t a good fix for my case… BUT you helped me realize I could make it work this by moving my nl2br function at the input level, instead of within my Bricks function—and I could pass the HTML along to Bricks.

Kudos!

1 Like