Skip Navigation

[Resolved] Content template is not being formatted

This support ticket is created 4 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by ericE-4 4 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1499843
Screenshot 2020-02-08 17.35.18.png
Screen Shot 2020-02-08 at 5.29.27 PM.png

I am using a view to build a series of HTML elements that have data attributes. One of the data attributes is pulled from a field that may have quotes, so those quotes need to be converted to their HTML entity (") before they are put into the data attribute, because the data attribute must itself have quotes around it. For example, if the field (called "Summary") value is:

this is text with "quotes" around it

the final HTML should look like this:

   data-summary="this is text with "quotes" around it"

In order to perform this conversion, I've created a shortcode, as follows:

add_shortcode( 'sanitize_text', 'sanitize_text_func');
function sanitize_text_func( $atts ) {
    $string = $atts['text'];
    return htmlspecialchars($string);
}

I've also created a content template ("sanitize-lodge-summary") to output the Summary field with the shortcode applied to it:

[sanitize_text text="[types field='summary' output='raw'][/types]"]

And finally I've added a the content template shortcode to the view:

... data-summary="[wpv-post-body view_template='sanitize-lodge-summary']" ...

However, when the page is rendered, the content template shortcode is not executed, i.e. the HTML has the literal content template shortcode in it (see image).

How do I fix this?

#1501075

Note that your form converts HTML entities to the character, so my text might be a little hard to read. It should say (I've used &quot-; so it won't convert)

...so those quotes need to be converted to their HTML entity (&quot 😉

the final HTML should look like this:

data-summary="this is text with &quot-;quotes&quot-; around it"
#1501099

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share the problem URL where you added the content template and access details so I can check the issue further.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1501119

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Please check now: hidden link

I've changed the shortcode as given under:

add_shortcode( 'sanitize_text', 'sanitize_text_func');
function sanitize_text_func( $atts ) {
    global $post;
   // $atts['text'] =  get_post_meta($post->ID,'wpcf-summary',true);
 //   $string = $atts['text'];
      $string =  get_post_meta($post->ID,'wpcf-summary',true);
    return htmlspecialchars($string);
}

Instead of using the content template, you need to use the [sanitize_text] shortcode directly as given under. Please replace it whereever you want to apply.

 data-summary="[sanitize_text]"
#1501989

My issue is resolved now. Thank you!