mod_harbour TEMPLATE/ENDTEXT

mod_harbour TEMPLATE/ENDTEXT

Postby Otto » Sun Jul 07, 2019 5: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: Select all  Expand view  RUN
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
 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: mod_harbour TEMPLATE/ENDTEXT

Postby Otto » Sun Jul 07, 2019 8:00 pm

Dear Antonio,
I think I found the answer in the Docs.
Best regards
Otto
https://github.com/FiveTechSoft/mod_har ... /Code-tips
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: mod_harbour TEMPLATE/ENDTEXT

Postby Otto » Mon Jul 08, 2019 6: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: Select all  Expand view  RUN
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

//----------------------------------------------------------------------------//
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: mod_harbour TEMPLATE/ENDTEXT

Postby Antonio Linares » Mon Jul 08, 2019 7:15 am

Dear Otto,

<?prg return cContent ?>
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: mod_harbour TEMPLATE/ENDTEXT

Postby Antonio Linares » Mon Jul 08, 2019 7:16 am

If you just want small sentences instead of entire functions then you can use BLOCKS instead of TEMPLATE:

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: mod_harbour TEMPLATE/ENDTEXT

Postby Otto » Mon Jul 08, 2019 7: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

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

********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: mod_harbour TEMPLATE/ENDTEXT

Postby Antonio Linares » Mon Jul 08, 2019 10:38 am

TEMPLATE PARAMS cContent
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: mod_harbour TEMPLATE/ENDTEXT

Postby Otto » Mon Jul 08, 2019 1: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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: mod_harbour TEMPLATE/ENDTEXT

Postby Antonio Linares » Tue Jul 09, 2019 8:05 am

Dear Otto,

work in progress...

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

Code: Select all  Expand view  RUN
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
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: mod_harbour TEMPLATE/ENDTEXT

Postby Antonio Linares » Tue Jul 09, 2019 8: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: Select all  Expand view  RUN
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
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: mod_harbour TEMPLATE/ENDTEXT

Postby Antonio Linares » Tue Jul 09, 2019 8:38 am

Dear Otto,

ok, this example is working fine :-)

blocks2.prg
Code: Select all  Expand view  RUN
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: mod_harbour TEMPLATE/ENDTEXT

Postby Antonio Linares » Tue Jul 09, 2019 9: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 53 guests