CMS
How to manage Quotes, Placeholders and Pre-Execute using VBScript within RedDot CMS
What’s Behind the Magic Curtain?
This code combines several techniques in a not-so-straightforward manner to get our desired result. Here’s the play-by-play:
In this section, assume the <%PageID%> info element is the value 1001 and <%stf_Label%> has the value My "Quoted" placeholder.
- Using JScript's toString() method on a function.
In the example above, we call stf_Label<%PageID%>.toString() in the ASP, but stf_Label<%PageID%> is a function defined in JScript! Yes you can call JScript functions in VBScript. By calling the "toString()" method on a function in JScript, we get the function body returned as a string. In this case
"function stf_Label1001() { //My "Quoted" placeholder }".
- Regular Expression Matching.
Using our function body string, we use the PlaceholderValueRegExp regular expression to find the placeholder value after the // characters.
Now we have a string value that properly contains a quote.
Putting it all together
In a real-world situation, you will want to put the GetPlaceholderValue function (and the preceding RegEx) in your master or foundation page so that it is only defined once. The extra if statement before the function stf_Label<%PageID%>() statement allows this code to be placed in a template that may occur multiple times on the same page.
Credits & Notes
The original article from Chad can be found here.
A similar approach by Adrian Mateljan for text elements using VBScript or PHP can be found here.
Feel free to share your thoughts in the comments below!
Related posts:
- RedDot & 301 Redirects: How to manage 301’s within your RedDot CMS projects
- RedDot CMS Render Tags – The Ultimate List
- RQL development with OpenText Web Site Management Server 11
- RedDot CMS API – or – RQL in a nutshell – Part 2
- Workaround – Placing red dots inside of OpenText CMS Render Tags
About the author:
Markus Giesen is a Solutions Architect and RedDot CMS Consultant, formerly based in Germany. Travelling around the world to find and offer solutions for a better world (in a very web based meaning). He just found a way to do this as part of a Melbourne based online consultant house. On this blog Markus shares his personal (not his employers) thoughts and opinions on CMS and web development. In his spare time you will find him reading, snowboarding or travelling. Also, you should
follow him on Twitter!
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?