Skip to content

a-h/templ-remote

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Remote components

Some apps need to allow users to customise the appearance of sections of the site.

With Go stdlib templates, it's possible to dynamically load templates, but templ components are compiled into Go code. Compiling to Go gives performance benefits, as well as compile time checking, but it makes it difficult to allow customisation of the site, because Go can't easily load and execute compiled code (e.g. dynamic loading of a DLL in C#).

However, we can use remote components.

In this design, a user writes a web server that implements the custom templates, and the application loads them dynamically, replacing the HTML content.

When the custom template server is running, you can access them via curl, e.g. curl -X POST --data '{"User":{"Name": "Adrian"}}' localhost:8090/header to render the header.

Tasks

run-app-without-custom

Running this will start the app without any custom templates. You will see "standard header" etc.

go run ./app/ serve

run-custom-templates

If you run the custom template server, then run run-app-with-custom, you will see "Custom header" etc.

go run ./custom/

run-app-with-custom

go run ./app/ serve --remote-templates-base-url="http://localhost:8090"

About

Demonstrate remote load of templ components.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors