Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add templates to version control #9

Open
patcon opened this issue Oct 24, 2018 · 4 comments
Open

Add templates to version control #9

patcon opened this issue Oct 24, 2018 · 4 comments

Comments

@patcon
Copy link

patcon commented Oct 24, 2018

Seems that the TemplateDirectory set in JSON config is not stored with the files? Can we add them in? This would seem to prevent me from confirming a resolution for #8 in the recommended way (using the meta element of pages).

Thanks for any consideration you can give this :)

@gslin
Copy link
Contributor

gslin commented May 8, 2020

You will need these files in TemplateDirectory:

  • askover18.html
  • bbsarticle.html
  • bbsindex.html
  • captcha.html
  • classlist.html
  • common.html
  • error.html
  • layout.html
  • manarticle.html
  • manindex.html
  • notfound.html

And you need ROOT in layout.html:

{{define "ROOT"}}
I am ROOT
{{end}}

@wade-fs
Copy link

wade-fs commented Jun 16, 2020

could anyone tell me how to compose these template files?
thx a lot

@gslin
Copy link
Contributor

gslin commented Dec 26, 2020

Hello @robertabcd, do you have any plan to do this, or some directions maybe?

@gslin
Copy link
Contributor

gslin commented Dec 28, 2020

After reading corresponding source code & spending some time on trial-and-error, I have found a way to write templates. You can read text/template and html/template manuals first, since pttweb uses them to render templates:

Then about the variables, you need to read pttweb.go as well, for example:

	return page.ExecutePage(w, &page.BbsArticle{
		Title:            ar.ParsedTitle,
		Description:      ar.PreviewContent,
		Board:            brd,
		FileName:         filename,
		Content:          template.HTML(string(ar.ContentHtml)),
		ContentTail:      template.HTML(string(ar.ContentTailHtml)),
		ContentTruncated: ar.IsTruncated,
		PollUrl:          pollUrl,
		LongPollUrl:      longPollUrl,
		CurrOffset:       ar.NextOffset,
	})

So in bbsarticle.html, you can use .Content:

{{- define "ROOT" -}}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<pre>
{{ .Content }}
</pre>
</body>
</html>
{{- end -}}

btw, you still need layout.html to include ROOT, because the system will check it:

{{- define "ROOT" -}}
{{- end -}}

Hope this will help you to build your own templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants