| Did you know ... | Search Documentation: |
| Grammar rule html//1 |
:- use_module(library(http/html_write)).
html(:Spec)//library(http/html_write). The differences are:
Var=Spec.
This processes Spec normally and binds Var to the
created element.The following terms are processed:
= Spec- Args&(Entity)<span> holding the entity otherwise.\ Rulecall(Rule), allowing for a user-defined rule. This
rule should call html//1 to
produce elements.:Rule\Rule, but calling in a module. This is the same as
\(M:Rule).Attr=Value.
If Value is a list, it is concatenated with a separating space. The
attribute names can either be the HTML name in lowercase or the DOM
camelCase attribute name. HTML names are mapped by the multifile
predicate html_dom/2.:- use_module(library(http/html_write)).
html(:Spec)//[]
\List
\Term
\Term but allows for invoking grammar rules in
external packages.
&<Entity>; or &#<Entity>;
if Entity is an integer. SWI-Prolog atoms and strings are
represented as Unicode. Explicit use of this construct is rarely needed
because code-points that are not supported by the output encoding are
automatically converted into character-entities.
Tag(Content)
Tag(Attributes, Content)Name(Value) or
Name=Value. Value is the atomic
attribute value but allows for a limited functional notation:
encode(Atom)location_by_id(ID)#(ID)location_by_id(ID).Name(Value). Values are encoded as in the encode option
described above.NAMES). Each value
in list is separated by a space. This is particularly useful for setting
multiple class attributes on an element. For example:
...
span(class([c1,c2]), ...),
The example below generates a URL that references the predicate
set_lang/1 in
the application with given parameters. The http_handler/3
declaration binds /setlang to the predicate set_lang/1
for which we provide a very simple implementation. The code between ...
is part of an HTML page showing the English flag which, when pressed,
calls set_lang(Request) where Request contains
the search parameter lang = en. Note that the
HTTP location (path) /setlang can be moved without
affecting this code.
:- http_handler('/setlang', set_lang, []).
set_lang(Request) :-
http_parameters(Request,
[ lang(Lang, [])
]),
http_session_retractall(lang(_)),
http_session_assert(lang(Lang)),
reply_html_page(title('Switched language'),
p(['Switch language to ', Lang])).
...
html(a(href(location_by_id(set_lang) + [lang(en)]),
img(src('/www/images/flags/en.png')))),
...