ThomasTJdev / nim_websitecreator

Nim fullstack website framework - deploy a website within minutes
https://nimwc.org
MIT License
176 stars 7 forks source link

Allow user to use DB-values inside blogpost #79

Open ThomasTJdev opened 5 years ago

ThomasTJdev commented 5 years ago

When writing a blogpost, the user has full control on what to show - HTML, CSS and JS. But what if the user want's to access data from the database, e.g. inserting the blog posts publication date just beneath the blog post heading?

Proposal:

Define certain strings, which would be replaced on rendering.

Problems:

It is to my knowledge not possible to query a string from the DB and execute Nim-code within it.

Suggestion:

I can't seem to find an elegant solution to this, so my proposal is:

  1. Prepare a multiReplace() on the queried string from the DB with certain elements such as publication date, views, category.

Example

# user edits a blog post from the browser interface
<div id="mainContainer" class="blogpost">
  <h1>New blog</h1>
  <div>${category}</div>
  <div>${views}</div>
<div>
# routes
get "/blog/newblogpage":
  let data = query-DB-to-fetch-data()
  resp data.multiReplace([("${category}", "Cats"), ("${views}", viewCount)])

Before

before

After

new

juancarlospaco commented 5 years ago

Use a Template instead of a Route :grey_question: See my implementation here for similar (but not same) kinda thing: https://github.com/ThomasTJdev/nim_websitecreator/pull/80#issue-261868873