Web Connection
Codeblocks in Response.ExpandTemplate()
Gravatar is a globally recognized avatar based on your email address. Codeblocks in Response.ExpandTemplate()
  George
  All
  May 4, 2020 @ 04:32pm

I am trying to make a "repeater" type of webpage using an expanded template.

The page works OK in itself, but this:

<% SCAN %>
   Name: <input id="txtName_<%= Tquery.Pk %>" name="txtName_<%= Tquery.Pk %>"
                      value="<%= TQuery.Name %>" />
   
<%  ENDSCAN  %>

Throws two errors.

Is this structure still possible?

George ...

Gravatar is a globally recognized avatar based on your email address. re: Codeblocks in Response.ExpandTemplate()
  Rick Strahl
  George
  May 4, 2020 @ 07:36pm

Yes that should work assuming TQuery is the active cursor and the field names are in the cursor.

I would make sure with:

<% 
select TQuery
SCAN 
%>

<% ENDSCAN %>

Note you might also want to make sure the text value is HTML Encoded so:

<input id="txtName_<%= Tquery.Pk %>" 
       name="txtName_<%= Tquery.Pk %>"
       value="<%: TQuery.Name %>" />

Notice the <%: Tquery.Name %> which HTML encodes the text to avoid scripting attacks and formatting errors for certain characters with your text input.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Codeblocks in Response.ExpandTemplate()
  George
  Rick Strahl
  May 4, 2020 @ 08:08pm

Thanks Rick,

Still no joy. I pasted the code as you suggested, like this from VSCode window.

 <% 
                select TQuery
                SCAN 
                %>
                <input id="txtName_<%= Tquery.Pk %>" name="txtName_<%= Tquery.Pk %>"
                      value="<%: TQuery.Name %>" />
                <% ENDSCAN %>

This is what renders on the Web Page. My Cursor is in scope and the first name is the string as shown below.

< % ERROR: select TQuery SCAN % > 849514-13< % ERROR: ENDSCAN % >

Any ideas? PS am using 712, and get the same results on two machines now.

George

Gravatar is a globally recognized avatar based on your email address. re: Codeblocks in Response.ExpandTemplate()
  George
  Rick Strahl
  May 4, 2020 @ 08:49pm

Hi Rick,

Quick update:

I installed the mainenance patch that you just released just now.

I recompiled everything inc. the classes and classlibs.

Still getting the error 😦

George ...

Gravatar is a globally recognized avatar based on your email address. re: Codeblocks in Response.ExpandTemplate()
  Tore Bleken
  Rick Strahl
  May 4, 2020 @ 11:16pm

Rick,

please pardon me for jumping in.

I don't recall ever having seen the <%: construct before, is that new? Also, I don't find it mentioned in the documentation.

Gravatar is a globally recognized avatar based on your email address. re: Codeblocks in Response.ExpandTemplate()
  Rick Strahl
  Tore Bleken
  May 5, 2020 @ 12:10am

No it's not new. It's been in there since 5.50 I think. We've talked about it in the Web Connection training a bunch. It's not a very high profile item and I realized today that it wasn't documented real well.

I added it here:

Templates and Scripts

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Codeblocks in Response.ExpandTemplate()
  Rick Strahl
  George
  May 5, 2020 @ 12:13am

With the code you have make sure you are using ExpandScript() not ExpandTemplate().

Templates can't execute continuous code like a SCAN loop between multiple code blocks. Scripts can because they compile down into PRG files that are executed.

Response.ExpandScript()

Read more here:

Templates and Scripts

and here:

Templates vs. Scripts

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Codeblocks in Response.ExpandTemplate()
  Tore Bleken
  Rick Strahl
  May 5, 2020 @ 01:16am

You don't expect me to remember every little detail, do you? 😃

Gravatar is a globally recognized avatar based on your email address. re: Codeblocks in Response.ExpandTemplate()
  Rick Strahl
  Tore Bleken
  May 5, 2020 @ 02:37am

Oh yes I do!

There will be a quiz next week! 😄

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Codeblocks in Response.ExpandTemplate()
  Tore Bleken
  Rick Strahl
  May 5, 2020 @ 03:03am

Challenge accepted! 😃

Gravatar is a globally recognized avatar based on your email address. re: Codeblocks in Response.ExpandTemplate()
  George
  George
  May 5, 2020 @ 10:31am

Thanks Rick,

I am sure that is my issue. The clue was in the subject...

Thanks for adding the documentation. All is MUCH clearer now.

George ...

© 1996-2020