Next to the standard <style> Element cweb framework features a <cstyle> Element.
CSS: inline vs. external
This is one of the more unusual parts of the system.
Normal <style>
A normal HTML <style> simply remains inline in the HTML.
No extra CSS function is generated for that.
<cstyle>
<cstyle> is a special tag of the templating system.
It has two modes:
<cstyle>withoutsetinline<cstyle setinline>
Mode A: <cstyle> without setinline
Then the generator treats the block as an external CSS source. It automatically generates a second function in addition to the HTML function:
char* home_template_css(page_data_t *data);
The main HTML function does not directly output the contents of the <cstyle> block in that case. Instead, the _css function returns the CSS text separately.
This is exactly how the example route uses it:
- generate CSS separately via
home_template_css(&data) - serve it under
/home/styles.css - then wire the HTML to that CSS path afterwards using
cweb_setAssetLink(...)
Mode B: <cstyle setinline>
Then the HTML output contains a real <style>...</style> block.
Additional attributes besides setinline are preserved and copied into the generated <style ...> tag.
What cweb_setAssetLink(...) does here
cweb_setAssetLink(...) works on the already generated HTML string:
- If it finds
href="logical_name", it rewrites it to the real path. - If it finds nothing, it inserts a new
<link rel="...">before</head>.
That is the mechanism used to bind external <cstyle> output to a real route.