Skip to content
This repository has been archived by the owner on Apr 30, 2019. It is now read-only.

How to use app variable in pages ? #84

Closed
usameavci opened this issue Jun 14, 2016 · 4 comments
Closed

How to use app variable in pages ? #84

usameavci opened this issue Jun 14, 2016 · 4 comments
Labels

Comments

@usameavci
Copy link
Contributor

My index.js file is;

'use strict';

let aero = require('aero')
let app = aero()
let PouchDB = require('pouchdb');
let database = new PouchDB('http://localhost:5984/passsbanker');

app.database = database;
app.run()

I want, get db records in pages. Am i access to app variable in pages globally ?

@akyoto
Copy link
Collaborator

akyoto commented Jun 15, 2016

See template globals.

"Every Jade template has access to the app variable. Page templates can additionally access their own page data via the page variable."

Yes, you can access app as a special global in templates.

From a code design standpoint it makes more sense to query the database in the controller and pass the result to the template. The template should not care about where the data comes from. This would be a cleaner, recommended solution.

@usameavci
Copy link
Contributor Author

I read it documents but im not use app variable in templates. Im using in controller file. What should i do ?

@akyoto
Copy link
Collaborator

akyoto commented Jun 20, 2016

Inside a controller method:

this.app
this.page

@usameavci
Copy link
Contributor Author

I tested your code just now and that works. Thanks!

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

No branches or pull requests

2 participants