NetTalk Central

Author Topic: Method to substitute <!-- Net:s:SessionVariable --> in HTML?  (Read 8625 times)

JohanR

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
    • Email
Method to substitute <!-- Net:s:SessionVariable --> in HTML?
« on: November 07, 2026, 06:03:15 AM »
Hi,

I have some HTML loaded in a session variable.
the HTML contains a tag <!-- Net:s:SessionVariable -->

Is there a method that will parse/substitute the tags?

thanks

Johan


osquiabro

  • Hero Member
  • *****
  • Posts: 728
    • View Profile
    • Email
Re: Method to substitute <!-- Net:s:SessionVariable --> in HTML?
« Reply #1 on: November 07, 2026, 06:33:14 AM »
yes you can with string Theory, example of my code

 Htm:TemplateId = 3
        GET(HtmlTemplates,Htm:PK_HtmlTemplates)
        IF ~ERROR()
            Loc:HTML = Htm:TemplateHTML
            st.SetValue(Loc:HTML)         
            st.replace('@nombre@',p_web.GSV('nombre'))
            st.replace('@fechadepago@',format(p_web.GSV('Afi:FechaPago_DATE'),@d03))
            st.replace('@cantidadpagada@',FORMAT(p_web.GSV('Afi:CantidadPagada'),@n$6.2))
            st.replace('@referencia@',p_web.GSV('Afi:NumeroPago' ))
            st.replace('@recibo@',p_web.gsv('Afi:NumeroPago'))
            Loc:HTML = st.Getvalue()       
            Loc:TemplateSubject = Htm:TemplateSubject
            st.SetValue(Loc:TemplateSubject)               
            Loc:TemplateSubject = st.Getvalue()
        END
        Access:HtmlTemplates.Close()       

JohanR

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
    • Email
Re: Method to substitute <!-- Net:s:SessionVariable --> in HTML?
« Reply #2 on: November 07, 2026, 09:52:16 PM »
Hi,

Yes, thanks, I can certainly do manual replace exercise.
Was wondering if there was a handy NT function that does the same as the tag replacement with the static files.
Using the NT functions would be preferable as it would work for all cases and follow the NTWS method of doing it.

thanks

Johan

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11345
    • View Profile
Re: Method to substitute <!-- Net:s:SessionVariable --> in HTML?
« Reply #3 on: November 17, 2026, 03:21:06 PM »
typically it's done for you. But it depends on the context. So tell us more about what HTML you are using here?

JohanR

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
    • Email
Re: Method to substitute <!-- Net:s:SessionVariable --> in HTML?
« Reply #4 on: November 19, 2026, 03:04:24 AM »
Hi Bruce

I have a form with a display field, this contains an HTML snippet, and the HTML also has some dynamic data from variables.
Currently I have the snippet in a file on disk and the display field source is a file tag.
The dynamic data is updated when the field is refreshed.

However if the HTML is pre-loaded in a session variable the dynamic data is not updated if the field is refreshed.

I have tried to follow the difference in code between the file tag and session variable, but not sure of the code that triggers the replacing of the tags eg. <!-- Net:s:cli:email -->

In the past I have used a procedure to generate HTML and then did the replacing by hand, so it's do-able.
As there are other tags available, like host besides session.

Would just be handy if the builtin methods can be used or triggered.

a simple example

<dl class="rows">
      <div class="row">
       <dt>
        Full name
       </dt>
       <dd data-value="fullName">
        <!-- Net:s:cli:first_name --><!-- Net:s:cli:name -->
       </dd>
      </div>
      <div class="row">
       <dt>
        Email
       </dt>
       <dd data-value="email">
        <!-- Net:s:cli:email -->
       </dd>
      </div>
      <div class="row">
       <dt>
        Mobile
       </dt>
       <dd data-value="mobile">
        <!-- Net:s:cli:cell_nr -->
       </dd>
      </div>
</dl>


thanks

Johan



 


Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11345
    • View Profile
Re: Method to substitute <!-- Net:s:SessionVariable --> in HTML?
« Reply #5 on: November 22, 2026, 07:38:24 PM »
>> However if the HTML is pre-loaded in a session variable the dynamic data is not updated if the field is refreshed.

It's not going to parse the contents of session values. I think that's the root of your problem here. You're not injecting HTML, you're injecting a session value, which happens to contain HTML.

JohanR

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
    • Email
Re: Method to substitute <!-- Net:s:SessionVariable --> in HTML?
« Reply #6 on: November 23, 2026, 08:59:39 AM »
Hi Bruce

Thanks , confirms what is happening.

If source is RAW, HTML either typed in the box or loaded from a session var does not parse the HTML and replace tags.

It works quite well if source is FILE.
Thinking it can be quite handy if the RAW source was also parsed and loaded from a session variable.
Would avoid the multiple disk file reads if there are a few of these on a page.

regards

Johan


JohanR

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
    • Email
Re: Method to substitute <!-- Net:s:SessionVariable --> in HTML?
« Reply #7 on: November 23, 2026, 09:10:06 PM »

Hi Bruce

Forgot to add,
I can create a function to do a manual replace, however if there was one or 2 methods I can use that does the Parse/replace that will be ideal, as it will use the existing rules.

thanks

Johan