Forum Discussion
Reference an iRule variable in an HTML iFile response
- May 08, 2013I think the subst Tcl command is closest to what you want:
HTTP::respond 200 content [subst -nocommands -nobackslashes [ifile get error_html]]
Very clean, and much safer than using eval.
It is possible, albeit a little tricky.
when HTTP_REQUEST {
set http_host [HTTP::host]
set http_uri [HTTP::uri]
eval "set temp \"[string map {"\"" "\\\""} [ifile get down.html]]\""
HTTP::respond 200 content $temp
}
You can also just do:
HTTP::respond 200 content [eval "set temp \"[string map {"\"" "\\\""} [ifile get down.html]]\""]
You can use local variables and commands (ie. [HTTP::host]) inside the HTML files as well. Essentially what you're doing is assigning the contents of the HTML file to a local variable, encapsulating the whole thing in quotation marks to make it one long string, replacing all of the internal quotation marks with escaped quotation marks, and then evaluating the new string to replace all of the inline variables and commands. You have to be careful of course that you don't have any TCL errors in your HTML, as that'll be a little less forgiving in the troubleshooting department. Also, if you have any other special characters in your HTML, like the square brackets, you'll need to escape them too.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com