I have 2 questions:
- Is the use of percent signs to delimit the so-called “placeholder” string, “STATE” dictated by something I can’t directly observe as I go through the tutorial? Perhaps it is dictated by something with one of the async libraries I’m using? I don’t see it mentioned anywhere within the HTML literature.
- I can clearly see that the “processor” function requires a parameter of type “String”. Nowhere in the code do I see a reference to the “processor” function with a parameter being supplied! The question is “How does the function get it’s parameter? Since the function is a parameter to the “send” method of the “request” object, I suppose the function is called by the “send” method and it is the “send” method that provides the string “STATE”? BUT HOW? Is it the case that the “processor” function (aka “Handler function”) is supposed to scan the HTML looking for strings within percent signs and return those strings?
Thanks, Ray
Hi.
The placeholder works with the Asyncwebserver library, it has nothing to do with HTML literature.
The Asyncwebserver library finds the placeholders and replaces them with whatever we define in the processor function. This is done automatically in the background.
You are correct about what you mention in bullet 2. It is how it happens.
Regards,
Sara
Sara,
Thanks. I found some good info here:
Basically, the idea is that the HTTP server provides a service we call “Template Processing”, whereby we can embed replaceable strings in the HTML and then retrieve them via the server’s call of our template processing function which then returns whatever we wish to replace the “replaceable string” with.
In our case we replace “STATE” with either “ON” or “OFF”. This allows us to merge static HTML with something we only know at runtime thereby modifying our HTML “on the fly”.
It was some years ago when I first encountered this concept — I had forgotten about it.
I also forgot about Lambda functions which is why I struggled to understand the syntax of
"[](AsyncWebServerRequest(*request){ ... }".
Thanks again, Ray