I am trying to create a library which will contain a function to send a html page. This function will load a pagea from SPIFFS and replace variables with values, like "Hi %name%, how are you" should translate to "Hi Name, how are you". I do this with the following function (it is not yet generic for page name. This will follow):
void serverSendPage (WiFiClient client, String paramName[], String paramValue, int n) {
if (client) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
client.println("<!DOCTYPE HTML>");
if (SPIFFS.exists("/page/index.php")) {
File f = SPIFFS.open("/page/index.php","r");
while(f.available()) {
String line = f.readStringUntil('\n');
for (byte i=0;i<n;i++) {
line.replace("%"+paramName+"%",paramValue[i]);
}
client.println(line);
}
}
delay(1);
client.stop();
}
}
This works if I send 2 String arrays. What I want to do however is #define the names and only have the values as actual String array, like this:
#define NAMES { "name", "color", "food" }
....
String values[3];
values[0] = "Name";
values[1] = "Blue";
values[2] = "Bread";
serverSendPage(client,NAMES,values,3);
This however does not work. I get an error:
cannot convert '' to 'String*' for argument '2' to 'void serverSendPage(WiFiClient, String*, String*, int)'
Since the NAMES will not change during the exection of the program, I wanted to have them defined as some sort of array.
What can I do to accomplish this?
BTW, I have tried by just sending the values with a count and replace %0% with a valuue etc. This works but if possible I want to use meaningful names in my code instead of numbers.
Any suggestions?