Quantcast

Passing arguments between WebPages

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Passing arguments between WebPages

Tobias Boege-2
Hi Benoit (or gb.web experts),

I have two questions about argument passing with WebPages (gb.web),
when I include one webpage into another with the <<OtherPage>> syntax.

(1) The first situation is that I have a small widget encapsulated in a
WebPage, let's say it is a specially formatted button MyButton.webpage.
It expects to be included with a text to put on the button:

  <<MyButton text="label">>

I want to be able to pass the value of a local variable of my parent
WebPage inside this argument like this (which doesn't work):

  <% For Each iInd = 0 To AllButtons - 1 %>
    <<MyButton text=Subst$("Button #&1", iInd)>>
  <% Next %>

Is this possible? A workaround here would be to define a function in the
parent WebPage which creates and renders an instance of MyButton and call
that, resulting in something like:

  <% For Each iInd = 0 To AllButtons - 1 %>
    <%= RenderButton(Subst$("Button #&1", iInd)) %>
  <% Next %>

This is good enough but I'm curious if the <<WebPage>> syntax admits
the other kind of argument passing somehow, as I think it would make
the parent WebPage prettier.

(2) The other question is about receiving arguments. If I'm a child page
and the parent included me by setting the "text" argument (like in (1)),
then I can print the "text" value via the special syntax

  <%!text>

But I want to use this value inside a <% Code %> or <%= Expr %> section,
to evaluate or manipulate it (this also doesn't work, but hopefully gets
my question across):

  <%= Subst$(!text, "#", "No. ") %>

For instance, is there a hidden Collection containing all the passed
arguments somewhere in the scope in which <% Code %> and <%= Expr %>
execute?

Regards,
Tobi

--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Passing arguments between WebPages

PICCORO McKAY Lenz
2017-05-18 11:14 GMT-04:00 Tobias Boege <[hidden email]>:

> Hi Benoit (or gb.web experts),
>

well, we are all like bruce lee with Jeet Kune Do! still starting so still
ther are not xperts yet!

that behaviour u described its similar to those used to parse in
codeigniter! i have very interest in
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Passing arguments between WebPages

Tobias Boege-2
In reply to this post by Tobias Boege-2
On Thu, 18 May 2017, Tobias Boege wrote:

> (2) The other question is about receiving arguments. If I'm a child page
> and the parent included me by setting the "text" argument (like in (1)),
> then I can print the "text" value via the special syntax
>
>   <%!text>
>
> But I want to use this value inside a <% Code %> or <%= Expr %> section,
> to evaluate or manipulate it (this also doesn't work, but hopefully gets
> my question across):
>
>   <%= Subst$(!text, "#", "No. ") %>
>
> For instance, is there a hidden Collection containing all the passed
> arguments somewhere in the scope in which <% Code %> and <%= Expr %>
> execute?
>

Turns out there is and it's called _Arg. (It didn't occur to me before that
I should look at gb.web's source code as well; I only tried to understand
gbc_form_webpage.c). So the following demonstrates that what I wanted is
possible (although not documented, so nobody should use it, of course):

  <%= _Arg!text %>

is the same as

  <%! text %>

Regards,
Tobi

--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Passing arguments between WebPages

Tobias Boege-2
In reply to this post by Tobias Boege-2
On Thu, 18 May 2017, Tobias Boege wrote:

> Hi Benoit (or gb.web experts),
>
> I have two questions about argument passing with WebPages (gb.web),
> when I include one webpage into another with the <<OtherPage>> syntax.
>
> (1) The first situation is that I have a small widget encapsulated in a
> WebPage, let's say it is a specially formatted button MyButton.webpage.
> It expects to be included with a text to put on the button:
>
>   <<MyButton text="label">>
>
> I want to be able to pass the value of a local variable of my parent
> WebPage inside this argument like this (which doesn't work):
>
>   <% For Each iInd = 0 To AllButtons - 1 %>
>     <<MyButton text=Subst$("Button #&1", iInd)>>
>   <% Next %>
>
> Is this possible? A workaround here would be to define a function in the
> parent WebPage which creates and renders an instance of MyButton and call
> that, resulting in something like:
>
>   <% For Each iInd = 0 To AllButtons - 1 %>
>     <%= RenderButton(Subst$("Button #&1", iInd)) %>
>   <% Next %>
>
> This is good enough but I'm curious if the <<WebPage>> syntax admits
> the other kind of argument passing somehow, as I think it would make
> the parent WebPage prettier.
>

Hrrm, so after reading main/gbc/gbc_form_webpage.c more attentively, I have
learned that this is also possible without weird hacks, and the syntax is
also sound, just a small bit different from what I imagined it would look
like above. *Instead of*

  <<MyButton text=Subst$("Button #&1, iInd)>>

you have to wrap the expression you want to evaluate inside <%=%>, so this
works as I wanted it to:

  <<MyButton text=<%= Subst$("Button #&1", iInd) %>>>

(On a tangent, I once designed a very simple (yet Turing-complete) text
substitution "programming language" on top of Gambas. The abundance of
angular brackets and special symbols above kind of reminds me of it --
you could only produce "write-only" code in that language.)

Sorry for the noise, but there's still hope that this can still help others
in the future.

Regards,
Tobi

--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Loading...