QGIS Server GetFeatureInfo custom CSS (or better: templates!)
there have been some requests in the past about custom CSS for html
GetFeatureInfo responses from QGIS Server.
Currently, the HTML response template is hardcoded and there is no way
to customize it, the Python plugin support introduced with the latest
version of QGIS Server provide some easy ways to add some custom CSS
rules or even provide custom templates.
To get you started, I've added a new filter to my example HelloServer plugin:
This filter is pretty simple, if the request is a WMS GetFeatureInfo
with HTML format, it injects a STYLE tag into the HTML HEAD.
As an exercise left to the reader, you can also intercept the call in
requestReady(self), change the INFO_FORMAT to text/xml and then do
some real templating, for example by using XSLT or pasrsing the XML
and injecting the values into a custom template.
Thanks a lot for your work Alessandro! Simple filter for a big problem! Finally we have apply our styles to the GetFeatureInfo response with your GetFeatureInfoCSSFilter.py, where we have directly insert the CSS parameters (without templates).
Now, we need to increase the control about this GetFeatureInfo response in two ways:
The first case is that, the attributes of my layers who are URL (http://...) can be understood as links for the QGIS Server and displayed with linkstyles that I've been included in the GetFeatureInfoCSSFilter.
The second is that, the response of my GetFeatureInfo request, for now show me all the layers of my QGSProject, included the layers with NO INFO values at the point of my request (show me only the header of the atributte table, without info). How can I do that the response hide the headers of the attribute table layers with NO INFO values?
Any Filter? Templates?
I have seen that in the Web Client you can modify the globaloptions.js to setup some of this, but I'm not sure they take effect in the QGIS Server response, outside Web Client.
You can decide to manipulate the GetFeatureInfo response in the client or in the server.
In the first case, you will use the options given in QGIS Web Client (and IIRC there is one to show URLs as links), in the latter you will use a QGIS Server Python plugin.
In my article  you can find a working example of server side filtering, for a very simple REGEXP substitution (string injection) but also a final hint about further and more complex output filtering. From that point it's up to you but there is basically nothing left in QGIS domain: it's everything pretty standard text manipulation or XML templating/transformation. As long as you have your XML parsed into an object you can also check for the presence of results in a layer and decide what to do in you final output.