FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour mod_harbour TEMPLATE/ENDTEXT
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
mod_harbour TEMPLATE/ENDTEXT
Posted: Sun Jul 07, 2019 05:49 PM
Hello Antonio,
How do I insert and show Harbour code inside TEMPLATE/ENDTEXT
How do I insert and show JS code inside TEMPLATE/ENDTEXT
Thank you in advance
Otto


Code (fw): Select all Collapse
function Controller( cRequest )

   cContent = If( Empty( cRequest ), "home",;
                  If( cRequest $ "wishlist,login,cart,checkout", cRequest, "home" ) )
  
TEMPLATE
   <h1>My First Heading</h1>
   <p>My first paragraph.</p>
    
ENDTEXT   

? cContent
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: mod_harbour TEMPLATE/ENDTEXT
Posted: Sun Jul 07, 2019 08:00 PM

Dear Antonio,
I think I found the answer in the Docs.
Best regards
Otto

https://github.com/FiveTechSoft/mod_har ... /Code-tips

Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: mod_harbour TEMPLATE/ENDTEXT
Posted: Mon Jul 08, 2019 06:45 AM
Dear Antonio,
can you please tell me why I get an error in this function.
<?prg cContent ?><br>
What is the right syntax to show variables?

Thank you in advance and best regards
Otto

I tried to insert these in eshop/index.prg
Code (fw): Select all Collapse
function Controller( cRequest )

   cContent = If( Empty( cRequest ), "home",;
                  If( cRequest $ "wishlist,login,cart,checkout", cRequest, "home" ) )
  
TEMPLATE
    <h1>My First Heading</h1>
   <p>My first paragraph.</p>
  Test<br>
     <?prg Time() ?><br>
     Otro<br>
     <?prg DToC( Date() ) ?> <br>
      Test show cContent<br>
     <?prg cContent ?><br>
     
     
     Si, ok<br>
       
ENDTEXT
  do case
case AP_Method() == "GET"
         AP_RPuts( View( "default" ) )

      case AP_Method() == "POST"
         do case
            case cRequest == "login"
                 Login() 
         endcase 
   endcase   

return nil

//----------------------------------------------------------------------------//
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: mod_harbour TEMPLATE/ENDTEXT
Posted: Mon Jul 08, 2019 07:15 AM

Dear Otto,

<?prg return cContent ?>

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: mod_harbour TEMPLATE/ENDTEXT
Posted: Mon Jul 08, 2019 07:16 AM
If you just want small sentences instead of entire functions then you can use BLOCKS instead of TEMPLATE:

Code (fw): Select all Collapse
BLOCKS
   Any text or HTML or whatever...
   {{Time()}}
ENDTEXT
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: mod_harbour TEMPLATE/ENDTEXT
Posted: Mon Jul 08, 2019 07:56 AM
Dear Antonio,
I am doing something wrong. Can you please help me again.
cContent is declared as STATIC
Thank you in advance
Otto






error: Variable does not exist CCONTENT


function Controller( cRequest )

cContent = If( Empty( cRequest ), "home",;
If( cRequest $ "wishlist,login,cart,checkout", cRequest, "home" ) )

TEMPLATE
<h1>My First Heading</h1>
<p>My first paragraph.</p>
Test<br>
<?prg Time() ?><br>
Otro<br>
<?prg DToC( Date() ) ?> <br>
Test show cContent<br>
Si, ok<br>

ENDTEXT

BLOCKS
{{ cContent }}
ENDTEXT



do case
case AP_Method() == "GET"
AP_RPuts( View( "default" ) )

case AP_Method() == "POST"
do case
case cRequest == "login"
Login()
endcase
endcase

return nil

//----------------------------------------------------------------------------//


<?prg return cContent ?>


error: Variable does not exist CCONTENT

called from: GETERRORINFO, line: 103
called from: DOBREAK, line: 114

function Controller( cRequest )

cContent = If( Empty( cRequest ), "home",;
If( cRequest $ "wishlist,login,cart,checkout", cRequest, "home" ) )

TEMPLATE
<h1>My First Heading</h1>
<p>My first paragraph.</p>
Test<br>
<?prg Time() ?><br>
Otro<br>
<?prg DToC( Date() ) ?> <br>
Test show cContent<br>
Si, ok<br>

<?prg return cContent ?>
ENDTEXT



do case
case AP_Method() == "GET"
AP_RPuts( View( "default" ) )

case AP_Method() == "POST"
do case
case cRequest == "login"
Login()
endcase
endcase

return nil

//----------------------------------------------------------------------------//

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: mod_harbour TEMPLATE/ENDTEXT
Posted: Mon Jul 08, 2019 10:38 AM

TEMPLATE PARAMS cContent

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: mod_harbour TEMPLATE/ENDTEXT
Posted: Mon Jul 08, 2019 01:29 PM

Dear Antonio,
thank you.
TEMPLATE PARAMS cContent
is working perfect.

Can you please tell me how to do the same with

BLOCKS
Any text or HTML or whatever...
{{Time()}}

{{cContent}}

ENDTEXT
Best regards
Otto

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: mod_harbour TEMPLATE/ENDTEXT
Posted: Tue Jul 09, 2019 08:05 AM
Dear Otto,

work in progress...

#xcommand BLOCKS [ PARAMS [<v1>] [,<vn>] ] => #pragma __cstream | AP_RPuts( MyReplaceBlocks( %s, "{{", "}}" [,<(v1)>][+","+<(vn)>] [, @<v1>][, @<vn>] ) )

Code (fw): Select all Collapse
function MyReplaceBlocks( cCode, cStartBlock, cEndBlock, cParams, ... )

   local nStart, nEnd, cBlock
   local lReplaced := .F.
   
   hb_default( @cStartBlock, "{{" )
   hb_default( @cEndBlock, "}}" )

   while ( nStart := At( cStartBlock, cCode ) ) != 0 .and. ;
         ( nEnd := At( cEndBlock, cCode ) ) != 0
      cBlock = SubStr( cCode, nStart + Len( cStartBlock ), nEnd - nStart - Len( cEndBlock ) )
      cCode = SubStr( cCode, 1, nStart - 1 ) + ValToChar( &( cBlock ) ) + ;
      SubStr( cCode, nEnd + Len( cEndBlock ) )
          lReplaced = .T.
   end
   
return If( HB_PIsByRef( 1 ), lReplaced, cCode )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: mod_harbour TEMPLATE/ENDTEXT
Posted: Tue Jul 09, 2019 08:11 AM
This seems the be the right code:

#xcommand BLOCKS [ PARAMS [<v1>] [,<vn>] ] => #pragma __cstream | AP_RPuts( MyReplaceBlocks( %s, "{{", "}}" [,<(v1)>][+","+<(vn)>] [, @<v1>][, @<vn>] ) )

Code (fw): Select all Collapse
function MyReplaceBlocks( cCode, cStartBlock, cEndBlock, cParams, ... )

   local nStart, nEnd, cBlock
   local lReplaced := .F.
   
   hb_default( @cStartBlock, "{{" )
   hb_default( @cEndBlock, "}}" )
   hb_default( @cParams, "" )

   while ( nStart := At( cStartBlock, cCode ) ) != 0 .and. ;
         ( nEnd := At( cEndBlock, cCode ) ) != 0
      cBlock = SubStr( cCode, nStart + Len( cStartBlock ), nEnd - nStart - Len( cEndBlock ) )
      cCode = SubStr( cCode, 1, nStart - 1 ) + ;
              ValToChar( Eval( &( "{ |" + cParams + "| " + cBlock + " }" ), ... ) ) + ;
      SubStr( cCode, nEnd + Len( cEndBlock ) )
          lReplaced = .T.
   end
   
return If( HB_PIsByRef( 1 ), lReplaced, cCode )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: mod_harbour TEMPLATE/ENDTEXT
Posted: Tue Jul 09, 2019 08:38 AM
Dear Otto,

ok, this example is working fine :-)

blocks2.prg
Code (fw): Select all Collapse
#xcommand BLOCKS [ PARAMS [<v1>] [,<vn>] ] => ;
   #pragma __cstream | AP_RPuts( MyReplaceBlocks( %s, "{{", "}}" [,<(v1)>][+","+<(vn)>] [, @<v1>][, @<vn>] ) )

function Main()

   local cValue := "Hello world"

   BLOCKS PARAMS cValue
      I can freely write here any text but also I can use my local vars:
      {{cValue}}
      so it seems to work fine ;-)
   ENDTEXT

return nil

function MyReplaceBlocks( cCode, cStartBlock, cEndBlock, cParams, ... )

   local nStart, nEnd, cBlock
   local lReplaced := .F.
   
   hb_default( @cStartBlock, "{{" )
   hb_default( @cEndBlock, "}}" )
   hb_default( @cParams, "" )

   while ( nStart := At( cStartBlock, cCode ) ) != 0 .and. ;
         ( nEnd := At( cEndBlock, cCode ) ) != 0
      cBlock = SubStr( cCode, nStart + Len( cStartBlock ), nEnd - nStart - Len( cEndBlock ) )
      cCode = SubStr( cCode, 1, nStart - 1 ) + ;
              ValToChar( Eval( &( "{ |" + cParams + "| " + cBlock + " }" ), ... ) ) + ;
      SubStr( cCode, nEnd + Len( cEndBlock ) )
          lReplaced = .T.
   end
   
return If( HB_PIsByRef( 1 ), lReplaced, cCode )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: mod_harbour TEMPLATE/ENDTEXT
Posted: Tue Jul 09, 2019 09:09 AM

Otto,

There is a new mod_harbour with BLOCKS PARAMS ... support

I have updated it in your server ;-)

Please test the new example blocks2.prg

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion