HTML publication using resources

Sometimes, the Simplicité HTML publication template can get messy as the publication gets complex. One way around this is to parameter your publication to use a method publication instead of a template publication of file publication, and have this method serve a HTML page.

When generating this page, your can append resources (linked either to the object or to the disposition), so you can keep your HTML, CSS and JS nicely split across diferent files:

OBJECT CONFIG

MyObject
- Publication
  - MyPublication
    - Usage: lists
    - Grantable: no
    - MIME Type: HTML
    - Type: Method
    - Method: pub
- Ressource
  - OBJECT_HTML_RESSOURCE_CODE
  - OBJECT_CSS_RESSOURCE_CODE

OBJECT CODE :

For more options, see HTMLTool and BootstrapWebPage

public String pub(){
	BootstrapWebPage wp = new BootstrapWebPage(
		HTMLTool.getRoot(), 
		"Webpage publication pattern example", 
		true
	);

        // APPENDING HTML TO PAGE
        // in this example, we populate the template server-side, 
        // but it could be done though JS on the client-side as well if it's gonna be dynamic
	wp.append(MustacheTool.apply(
		this,
		"OBJECT_HTML_RESSOURCE_CODE", 
		"{'rows':"+toJSON(search(), null, false, false)+"}"
	));
        // APPENDING CSS TO PAGE
        wp.appendCSSInclude(HTMLTool.getResourceCSSURL(this, "OBJECT_CSS_RESSOURCE_CODE"));

        // Return page
	return wp.toString();
}

OBJECT_HTML_RESSOURCE_CODE

<div class='alert alert-success'>Webpage publication pattern example</div>
<div class="container">
    <table class="table table-striped table-hover">
		{{#rows}}
		<tr>
			<td>{{fieldName}}</td>
		</tr>
		{{/rows}}
	</table>
</div>