How to manage Quotes, Placeholders and Pre-Execute using VBScript within RedDot CMS / Open Text Management Server This is another great guest post by Chad Killingsworth from the Missouri State university. Chad is another RedDot Guru who comes up with neat solutions every now and then and also integrated the TinyMCE texteditor into Open Text Websolutions Management Server RedDot CMS.
A frequent task in RedDot Open Text CMS template construction is to assign the value of a placeholder to a string so you can perform some kind of logic on it.
Most of the time we get along very well with our beloved content management system, but sometimes we wouldlike to add some kind of special characters to our standard text elements. And this works fine for 99%, no matter what we do, we can add a copyright-character, trademark, .. pretty much everything.
But one thing always breaks, and this is not even RedDot’s fault, it’s a simple ASP or VBScript flaw. Take this example:
<!IoRangePreExecute> <% dim label label = "<%stf_Label%>" %> <!/IoRangePreExecute>
If the <%stf_Label%> placeholder happens to contain an un-encoded quote, you'll get a server error. But sometimes you just really NEED a quote in the value. How do you handle this?
Server side JavaScript (or JScript) has long been supported, but rarely used, by Internet Information Server. In this case we can use the following code to correctly capture the value.
<!IoRangePreExecute>
<script language="javascript" runat="server">
var PlaceholderValueRegExp = /^function [_a-zA-Z][_a-zA-Z0-9]*(s*)s*{s*//([sS]*)}$/i;
function GetPlaceholderValue(PlaceholderFunctionString) {
var str = PlaceholderFunctionString.match(PlaceholderValueRegExp);
if(str != null && typeof(str) == "object")
return str[1];
else
return "";
}
if(!stf_Label<%PageID%>)
function stf_Label<%PageID%>(){
//<%stf_Label%>
}
</script>
<%
dim label
label = GetPlaceholderValue(stf_Label<%PageID%>.toString())
%>
<!/IoRangePreExecute>
And presto – you have your variable and your quotes too.
How does this work? What’s Behind the Magic Curtain?
Read more »
Pages:
it appears wordpress has chomped this up on the copy and paste from the original blog. this line
var PlaceholderValueRegExp =
/^function [_a-zA-Z][_a-zA-Z0-9]*(s*)s*{s*//([sS]*)}$/i;
needs to be split over a newline otherwise you get a sytax error. For anyone trying to paste this straight in to reddot do it from the original blog and you should be ok!
– Morgan
I’m using VB.NET in my current project for pre-executing. If someone may find it useful – it surely overcomes problems with quotes … I first write contents of the placeholder into invisible literal:
e.g.
Then I can process the text by grabbing it from the literal in the pre-execute block:
litBody.Text()
In some cases, literal cannot parse HTML code; I created ASP Server
Control, which will take anything between custom ASP tags and process it in function. All it needs installing a dll file on the CMS box. I can provide more details / sample code if someone interested.
Did not post this line in the example for some reason:
<asp:Literal runat=”server” ID=”litBody<%inf_PageGUID%>” Visible=”false”><%txt_Body%></asp:Literal>
Hi,
Is there a way to dynamically populate an option list placeholder with values from a database table?
Tracy
hi,
this script is very nice, but you can it only use on standardfields with singleline output.
For multiline fields (textfields) with crlf inside, can you use this solution.
replace the original regex with:
var PlaceholderValueRegExp = /^function [_a-zA-Z][_a-zA-Z0-9]*\(\s*\)\s*\{\s*\/\*([\s\S]*)\*\/\s*\}$/i;
and replace the function with:
function stf_Label(){
/*
<%stf_Label%>
*/
}
@Tracy, I would say: Yes. What exactly do you have in mind? Read the values from the template?
@BB: Nice one!
BB,
If you pre-execute .NET code – you can do textarea placeholder with the ASP:Literal.
Call me crazy, but can’t you negate the need to go to do all that by going:
<%
Dim label
label =
%>
can anyone give me a solution to connect two placeholders. for example
i want to connect a headline placeholder with a title(stf) placeholder
Hey Gourav, you can either reference one element to another or use RQL to copy the content from one element to the next one. What are you trying to do?