// you’re reading...

CMS

How to manage Quotes, Placeholders and Pre-Execute using VBScript within RedDot CMS


How to handle quotes in standard text elements with VBScriptHow 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?

Strange Bedfellows

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 »

Share and Enjoy:
  • Print
  • email
  • Twitter
  • Digg
  • Reddit
  • StumbleUpon
  • Google Bookmarks
  • del.icio.us
  • MisterWong
  • Facebook
  • LinkedIn

No related posts.

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