From e891b39dc2fb7fcbf545b4e379b0b1abae98c26d Mon Sep 17 00:00:00 2001 From: vinchent Date: Tue, 6 Aug 2024 13:56:39 +0200 Subject: [PATCH] Moving js to a reusable file and change the dir for the img --- cmd/web/handlers.go | 4 +- cmd/web/render.go | 2 +- cmd/web/templates/buy-once.page.gohtml | 7 +- cmd/web/templates/terminal.page.gohtml | 134 +------------------------ static/{ => img}/widget.jpeg | Bin 5 files changed, 9 insertions(+), 138 deletions(-) rename static/{ => img}/widget.jpeg (100%) diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index 6c06944..705e7f5 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -9,7 +9,7 @@ func (app *application) VirtualTerminal(w http.ResponseWriter, r *http.Request) stringMap["publishable_key"] = app.config.stripe.key if err := app.renderTemplate(w, r, "terminal", &templateData{ StringMap: stringMap, - }); err != nil { + }, "stripe-js"); err != nil { app.errorLog.Println(err) } } @@ -46,7 +46,7 @@ func (app *application) PaymentSucceeded(w http.ResponseWriter, r *http.Request) // ChargeOnce displays the page to buy one widget func (app *application) ChargeOnce(w http.ResponseWriter, r *http.Request) { - if err := app.renderTemplate(w, r, "buy-once", nil); err != nil { + if err := app.renderTemplate(w, r, "buy-once", nil, "stripe-js"); err != nil { app.errorLog.Println(err) } } diff --git a/cmd/web/render.go b/cmd/web/render.go index 951221f..5316472 100644 --- a/cmd/web/render.go +++ b/cmd/web/render.go @@ -80,7 +80,7 @@ func (app *application) parseTemplate( // build partials if len(partials) > 0 { for i, x := range partials { - partials[i] = fmt.Sprintf("tempaltes/%s.partial.gohtml", x) + partials[i] = fmt.Sprintf("templates/%s.partial.gohtml", x) } t, err = template.New(fmt.Sprintf("%s.page.gohtml", page)). Funcs(functions). diff --git a/cmd/web/templates/buy-once.page.gohtml b/cmd/web/templates/buy-once.page.gohtml index fc7ca4d..0e3cd0b 100644 --- a/cmd/web/templates/buy-once.page.gohtml +++ b/cmd/web/templates/buy-once.page.gohtml @@ -1,11 +1,11 @@ -{{ template "base" }} +{{ template "base" .}} {{ define "title" }} Buy one widget {{ end }} {{ define "content" }}

Buy One Widget


-widget @@ -79,3 +79,6 @@ Buy one widget value="payment_currency"> {{ end }} +{{ define "js" }} +{{ template "stripe-js" . }} +{{ end }} diff --git a/cmd/web/templates/terminal.page.gohtml b/cmd/web/templates/terminal.page.gohtml index c2b1395..3fb3511 100644 --- a/cmd/web/templates/terminal.page.gohtml +++ b/cmd/web/templates/terminal.page.gohtml @@ -76,137 +76,5 @@ Virtual Terminal {{ end }} {{ define "js" }} - - +{{ template "stripe-js" . }} {{ end }} diff --git a/static/widget.jpeg b/static/img/widget.jpeg similarity index 100% rename from static/widget.jpeg rename to static/img/widget.jpeg