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!