A
A
Andrey2017-05-01 12:24:55
Node.js
Andrey, 2017-05-01 12:24:55

How are widgets implemented in Express js?

All examples for the question are taken from here: https://developer.mozilla.org/en-US/docs/Learn/Ser...

Suppose, on the main page of the site, I display a list of books: And this is how I display information about a specific book:
router.get('/', book_controller.index);

router.get('/book/:id', book_controller.book_detail);

In this case, the book_controller methods return some object to me with data, possibly obtained from the database.
Everything is clear here.
But what if I want to show the username on all pages?
Do I need to write something like this in each route:
router.get('/book/:id', {
books: book_controller.book_detail,
user: user_controller.name );

And so for each page?
It would be more convenient to insert some special markup into the template, such as
(the example is abstract, not tied to any templating system).
And this very widget, if it is on the page, could request the data it needs.
But somehow I can’t integrate some entity into the template that would request data for itself. A template in Express "wants" to receive raw data and insert it into the markup.
Is it somehow possible to implement data output control in a template on Express, without prescribing each block in the routes?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question