[Gambas-user] Passing arguments between WebPages
Tobias Boege
taboege at ...626...
Thu May 18 18:03:25 CEST 2017
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
More information about the User
mailing list