The github repo for this post is here.
Assuming we have instances and initializations for the Postgres Auth backend and Postgresql-Simple Snaplet, we can do a few things. First, we need to write a Splice for the AuthUser data type. We will only use a couple fields to show how it works.
##, we are binding the strings
"userLoginCount" to their respective values from the
userLogin authUser gives us a
"userLogin" is bound to a text splice. We also
"userLoginCount" as a text splice by converting the
int we get from using
Now that we have our Splice written, let’s write our template.
Nothing major here. We have used the strings we bound before
as tags to display the text from the
Finally, we can write a Handler to make the database request and render the template using our splice.
Using a simple query to store the data from Postgres in
result, we then render using our template
auth_user_splice.tpl) and apply the splice to the data in
To display a list of data, the process is very similar.
We can reuse the
authUserSplice we just wrote and map it
across the list of data we plan on passing in using
We will also write a new template to display the
information. Included in this is the
authUsers tag, which
we are going to bind in our Handler.
We can then write our handler as such:
We are rendering our new template
with our mapped splices bound to
"authUsers". The code
<authUsers> will be run for each result in our
That's it. Feel free to pull the code from github and leave any questions you have below.