Forum OpenACS Development: Re: Cannot pass HTML5 meta data in xowiki using {{set-parameter}}

After much poking around I discovered that the {{set-parameter}} includelet merely sets up parameters in the context of the local connection. For the special cases 'lang', 'description', 'keywords', and 'html_title', these parameters are made accessible as variables within the Page object, and code in the view method of the Page object sets them as meta tags explicitly in a loop using template::head::add_meta.

However, as a general rule, parameters set using the {{set-parameter}} includelet are not set up as local properties of the page, and are not explicity written to meta tags.

By following through the code I discovered that parameters set by the {{set-parameter}} includelet are accessible via the parameter handing machinery of the ::xo::cc helper object. So by adding the following line to the section of code in the Page::view method that handles the setting of the meta tags, I was able to solve my problem by hard-coding the additional meta name that I wanted to add:

set meta(viewport) [xo::cc set perconnectionparam(viewport)]

In context that is:

...
      #
      # initialize and set the template variables, to be used by
      # a. adp_compile/ adp_eval
      # b. return_page/ adp_include
      #

      set header_stuff [::xo::Page header_stuff]
      if {[info command ::template::head::add_meta] ne ""} {
	set meta(language) [my lang]
	set meta(description) [my description]
	set meta(keywords) ""
	set meta(viewport) [xo::cc set perconnectionparam(viewport)]
	if {[my istype ::xowiki::FormPage]} {
	  set meta(keywords) [string trim [my property keywords]]
	  if {[my property html_title] ne ""} {
	    ::xo::Page set_property doc title [my property html_title]
	  }
	}
	if {$meta(keywords) eq ""} {
	  set meta(keywords) [$context_package_id get_parameter keywords ""]
	}
	foreach i [array names meta] {
	  # don't set empty meta tags
	  if {$meta($i) eq ""} continue
	  template::head::add_meta -name $i -content $meta($i)
	}
      }
...

The most important learning point for me is therefore that the {{set-parameter}} includelet is not a method for setting meta tags in the document header, but a means of setting parameters in the connection context.

My second conclusion is that I now have questions!

  1. Is this an appropriate way to do this?
  2. Would it be better to write a simple includelet specifically to add the appropriate includes and meta tags needed for JQuery Mobile, instead of serving them via [[js:includes]] and the above hack from xowiki?

After a bit more poking around, I think this is better:

set meta(viewport) [::xo::cc get_parameter viewport ""]

This avoids reaching under the skirt of the API, and also provides a means to grab the meta data if it exists, but to avoid throwing an error if it doesn't.

R.