// you’re reading...

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.

  1. 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 }".
  2. 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!

Share and Enjoy:
  • Print
  • email
  • Twitter
  • Digg
  • Reddit
  • StumbleUpon
  • Google Bookmarks
  • del.icio.us
  • MisterWong
  • Facebook
  • LinkedIn
Related posts:
  1. RedDot & 301 Redirects: How to manage 301’s within your RedDot CMS projects
  2. RedDot CMS Render Tags – The Ultimate List
  3. RQL development with OpenText Web Site Management Server 11
  4. RedDot CMS API – or – RQL in a nutshell – Part 2
  5. Workaround – Placing red dots inside of OpenText CMS Render Tags

Pages:

1 2

About the author:

Markus Giesen 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!

Discussion

10 comments for “How to manage Quotes, Placeholders and Pre-Execute using VBScript within RedDot CMS”

  1. 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

    Posted by Morgan Ritchings | May 11, 2010, 9:35 am
  2. 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.

    Posted by Vitaliy Rabotnik | May 11, 2010, 7:21 pm
  3. 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>

    Posted by Vitaliy Rabotnik | May 11, 2010, 7:23 pm
  4. Hi,

    Is there a way to dynamically populate an option list placeholder with values from a database table?

    Tracy

    Posted by Tracy Lee | May 21, 2010, 9:58 pm
  5. 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%>
    */
    }

    Posted by BB | May 25, 2010, 4:33 pm
  6. @Tracy, I would say: Yes. What exactly do you have in mind? Read the values from the template?
    @BB: Nice one!

    Posted by Markus Giesen | May 26, 2010, 6:26 am
  7. BB,

    If you pre-execute .NET code – you can do textarea placeholder with the ASP:Literal.

    Posted by Vitaliy Rabotnik | May 26, 2010, 2:28 pm
  8. Call me crazy, but can’t you negate the need to go to do all that by going:
    <%
    Dim label
    label =
    %>

    Posted by Robert Moore | July 11, 2010, 7:03 am
  9. can anyone give me a solution to connect two placeholders. for example
    i want to connect a headline placeholder with a title(stf) placeholder

    Posted by Gourav | January 14, 2011, 8:21 am
  10. 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?

    Posted by Markus Giesen | January 18, 2011, 1:27 am

Post a comment



Stay up to date! - Get notified about followup comments

If you don't feel the urge to comment but wish to stay in the loop:
Just enter your email and subscribe to new comments.

Subscribe without commenting

Recent Tweets

  • RT @AirKraft: Transport Canada breakout: they manage 80K pages and 300K assets with WSM(RedDot). Wow! #OTCW 2010-11-11
  • The RedDot usergroup session 'Future of WCM' is in National Harbor 7, now. See you there! #otcw 2010-11-11
  • RT @yttergren: @AirKraft: Calling all WSM(RedDot) devs: share your solutions on http://bit.ly/bgPIof EVERY solution can win an iPad #OTCW 2010-11-10
  • Come to the Solution Exchange session. Enhance your (#reddot) CMS project! Chesapeake 12, 3:20pm #otcw Looking forward to see you there! 2010-11-10
  • More updates...