PDA

View Full Version : escaping quotation marks in a template variable


coolegg
02-17-2012, 02:12 PM
I am redesigning one of my vB4 CMS widgets, "Recent Threads". It has variable for the preview of a thread post contents, it is called {vb:raw thread.previewtext}. I want to move it into the title attribute for the link to the thread (<a href="thread_url" title="thread_preview_text">) so that on most modern browsers the preview text will show up on hover over the link.

To work, I need to escape either double or single quotes from the text. Can I do this in a template? {vb:raw xxx} and {vb:urlencode xxx} aren't going to cut it for me. Is there an alternative that will escape my quotes?

If not, any other suggestions? I suppose I could do a plug-in(?) but that template has no hook, and I have always been perplexed how to do a plug-in when there is no template hook.

kh99
02-18-2012, 07:55 PM
It looks like {vb:escapejs xxx} escapes single quotes with a backslash (and that's all it does, apparently).

ForumsMods
02-19-2012, 03:17 AM
You can use:
{vb:var thread.previewtext}
The variable will be run through htmlspecialchars (http://php.net/manual/en/function.htmlspecialchars.php)