Assigning contents of a placeholder to ASP -- problems with quotes

115 views
Skip to first unread message

Simon Lewis, UK

unread,
Oct 22, 2008, 7:56:09 AM10/22/08
to RedDot CMS Users
Hi all,

I'm struggling with a really fundamental problem and wondering if
anyone has any bright ideas...

I need to put the contents of a standard text placeholder into an ASP
variable so that I can use ASP to manipulate the text. Here's the
only way I know how:

<%
my_asp_variable = "<%std_reddot_text_placeholder%>"
%>

That's perfect until someone puts a value in the placeholder that
contains a quote character, because when ASP reaches the quote
character, it thinks the string assignation has ended, and throws an
error on the remaining contents of the placeholder.

I thought of using the Replace function in various ways...

<%
my_asp_variable = Replace("<%std_reddot_text_placeholder%>", """",
Chr(34))
%>

<%
my_asp_variable = escape("<%std_reddot_text_placeholder%>")
%>


...but the simple truth is that the problem lies in the fact that
this:

"<%std_reddot_text_placeholder%>"

...is effectively turned into this:

"here is the text in my placeholder which contains "quoted" text"

I'm sure loads of other people have met this problem... any ideas on
how to get round it?

bushland25

unread,
Oct 22, 2008, 6:34:17 PM10/22/08
to RedDot CMS Users
Hi Simon,

I don't encounter the same problem as you when I read similar
placeholders in asp code. The value I get back from the placeholder is
in HTML, and so I get back something like &quot;Hello World&quot;. You
should check that the placeholder is output in HTML format to prevent
this from happening. When you edit the placeholder, check that the you
have 'Do not convert characters to HTML' unchecked.

On Oct 22, 4:56 am, "Simon Lewis, UK" <simon.le...@npia.pnn.police.uk>
wrote:

Jonathan W

unread,
Oct 23, 2008, 5:48:21 AM10/23/08
to RedDot CMS Users
Simon's solution sounds good. I also have an untested JavaScript trick
for this from RedDot UK, which puts the placeholder content inside a
JavaScript comment inside a JavaScript function, and uses
function.toString() to get at the function's source code and a regular
expression to extract it from the comment. Very clever, if it works -
looking at it I can't believe that you can call a JavaScript function
from inside ASP, but I've never used runat="server" before. Simon's
solution is cleaner as long as the change doesn't have any unwanted
side-effects.

<script language="JScript" runat="server">
function get_placeholder(name) {
var re = /\/\*((?:.|\n)*)\*\//;
return re.exec(eval("var_" + name + ".toString()"))[1];
}
function var_txt_content() {
/*<%txt_content%>*/
}
</script>
<%
txt_content = get_placeholder("txt_content")
%>

Simon Lewis, UK

unread,
Oct 23, 2008, 6:11:06 AM10/23/08
to RedDot CMS Users
Hi bushland25,

Thanks for your post. I had a play and found that what you say works
*as long as* you've got "Ascii text" switched on. If switched off,
then the "Do not convert..." setting has no effect either on or off.
(I was surprised at this, but that's definitely what happened.)

Oh well, that's still useful to know, so thanks!

Simon.


On Oct 22, 11:34 pm, bushland25 <bushlan...@gmail.com> wrote:

Simon Lewis, UK

unread,
Oct 23, 2008, 6:15:52 AM10/23/08
to RedDot CMS Users
Hi Jonathan,

Thanks for your post. I agree that it sounds way too good to be
true! I tried it, and unfortunately couldn't get it to work. That
said, I can't believe they'd post that JavaScript trick if it hadn't
at least worked somewhere, so I'd be interested to have the URL of
where you found it. Would you mind? Maybe there's some other setting
that I need to check in RedDot for it to work. It does seem odd
though that you can call a JS function from ASP... I've never seen
that done before. I tried a simpler version of calling a JS function
using ASP, and couldn't get even that to work. If you could send that
URL...? Many thanks.

Simon.

Luca Loguercio

unread,
Oct 23, 2008, 9:31:47 AM10/23/08
to RedDot-C...@googlegroups.com
Hi guys,

I've managed to get that JS trick to work, as well as other asp/JS
tricks where asp alone couldn't do what i needed.

I'll see if i can find the exact code I used and post it.

- Luca

Chris Peoples

unread,
Oct 23, 2008, 11:40:10 AM10/23/08
to RedDot CMS Users
Have you tried using render tags with the escape function? So, rather
than the placeholder, it would be:

<%
var = "<%!! Escape:HtmlEncode(Context:CurrentPage.Headline) !!%>"
%>

I haven't tried it before, but HTMLEncode should convert quotes to
&quot;.

On Oct 22, 4:56 am, "Simon Lewis, UK" <simon.le...@npia.pnn.police.uk>
wrote:

El Pollo Loco

unread,
Oct 23, 2008, 11:53:35 AM10/23/08
to RedDot CMS Users
How about using JScript
> > how to get round it?- Hide quoted text -
>
> - Show quoted text -

Simon Lewis, UK

unread,
Oct 24, 2008, 5:06:15 AM10/24/08
to RedDot CMS Users
Great! That seems to be the answer -- thanks so much. I hadn't used
render tags before, but I tried pasting your code into a template and
it worked. Actually, in my case, it's not the headline that I need to
put into a variable... I tried replacing "CurrentPage.Headline" with
"CurrentPage.txt_body" and that failed, BUT searching the web for
"reddot render tags" I found this syntax, which does do the trick:

var = "<%!!
Escape:HtmlEncode(Context:CurrentPage.Elements.GetElement(txt_body).Value) !!
%>"

Thanks again for suggesting render tags. A whole new area for me to
explore :o)
Reply all
Reply to author
Forward
0 new messages