These are chat archives for codefellows/sea-b15-javascript

28th
Oct 2014
Robert Talamantez
@Talamantez
Oct 28 2014 21:50
hey y'all - anyone know of a way to debug a handlebars partial block statement?
Dale Corns
@dcorns
Oct 28 2014 21:51
@Talamantez post thy code...hello
Robert Talamantez
@Talamantez
Oct 28 2014 21:54
hey dale
i've got a template views/partials/weather.handlebars
```
<div class="weatherWidget">

    {{#each partials.weather.locations}}
            <h3>{{name}}</h3>
    {{/each}}

    <small>Source: <a href="http://www.wunderground.com">Weather Underground</a></small>
</div>
Dale Corns
@dcorns
Oct 28 2014 21:57
your still in sf
Robert Talamantez
@Talamantez
Oct 28 2014 21:57
the widget is rendering, but its not showing anything from the each block
ya
for good looks like (Kat's got a job down here)
Dale Corns
@dcorns
Oct 28 2014 21:58
ok, so have you verified you have data in par.wea.location?
Robert Talamantez
@Talamantez
Oct 28 2014 21:59
yeah here is the code from the app.js file:
function getWeatherData(){
    return{
        locations: [
            {
                name: 'Portland' ,
                forecastUrl: 'http://www.wunderground.com/US/OR/Portland.html',
                iconUrl: 'http://icons-ak.wxug.com/i/c/k/cloudy.gif',
                weather: 'Overcast',
                temp: '54.1 F (12.3 C)',
            },
            ...,
        ],
    };
}

app.use(function(req, res, next){
    if(!res.locals.partials) res.locals.partials = {};
    res.locals.partials.weather = getWeatherData();
        console.dir(res.locals.partials.weather);
    next();
});
Dale Corns
@dcorns
Oct 28 2014 22:04
so i thought I saw a console.log of the data that then disappeared, I assume it is displaying an object array right? Sorry if too elementary here...maybe I should just ask, what is the problem you are having?
Robert Talamantez
@Talamantez
Oct 28 2014 22:05
oh, yeah sorry i took that out
uh, let's see
Dale Corns
@dcorns
Oct 28 2014 22:05
I assume your verified there is the expected data in the object, but the names are not being displayed on the page
Robert Talamantez
@Talamantez
Oct 28 2014 22:06
yes that's the problem i'm having
the console.dir prints out this:
{ locations: 
   [ { name: 'Portland',
       forecastUrl: 'http://www.wunderground.com/US/OR/Portland.html',
       iconUrl: 'http://icons-ak.wxug.com/i/c/k/cloudy.gif',
       weather: 'Overcast',
       temp: '54.1 F (12.3 C)' },
     { name: 'Bend',
       forecastUrl: 'http://www.wunderground.com/US/OR/Bend.html',
       iconUrl: 'http://icons-ak.wxug.com/i/c/k/partlycloudy.gif',
       weather: 'Partly cloudy',
       temp: '55.0 F (12.8 C)' },
     { name: 'Manzanita',
       forecastUrl: 'http://www.wunderground.com/US/OR/Manzanita.html',
       iconUrl: 'http://icons-ak.wxug.com/i/c/k/rain.gif',
       weather: 'Light Rain',
       temp: '55.0 F (12.8 C)' } ] }
Dale Corns
@dcorns
Oct 28 2014 22:08
have your tried this.name instead of just name? As I understand it, that is the way it is done.
Robert Talamantez
@Talamantez
Oct 28 2014 22:08
I will try that
hmm, yeah - I also tried just getting it to print anything based on the partials.weather.locations count, and that wouldn't come in either
so it looks like it's not seeing "par.wea.loc"
no success with 'this.name'
Dale Corns
@dcorns
Oct 28 2014 22:15
Yes forgive my handlebars ignorance, but you assigning the locations object array to res.locals.partials.weather and console logging the same, but...
Robert Talamantez
@Talamantez
Oct 28 2014 22:16
yeah - i addt ed a script in weather.handlebars to console.log 'partials' on the client - it says it's undefined
Dale Corns
@dcorns
Oct 28 2014 22:16
is res.locals a global
how about res.locals.partials.weather.locations ?
Robert Talamantez
@Talamantez
Oct 28 2014 22:19
yes it's looks like those are globals
Dale Corns
@dcorns
Oct 28 2014 22:20
if they are, rather than writing a script you should be able to see res.locals try to auto complete when you start to type it in the console on the client side
Robert Talamantez
@Talamantez
Oct 28 2014 22:21
yeah that's not coming up in the console
hmmm, yeah so the response object in the app goes back to through the handlebars template before it's rendered
Dale Corns
@dcorns
Oct 28 2014 22:24
Probably not exactly, handlebars is all client side, I would think you would need some sort of a controller that is responsible for loading the template on the client side.
what is it that receives the response from the server success:
app.use is on the server side right?
Robert Talamantez
@Talamantez
Oct 28 2014 22:26
ya app.use is on the server
Dale Corns
@dcorns
Oct 28 2014 22:26
so you are making a get request with a callback for err or datareturned right?
Robert Talamantez
@Talamantez
Oct 28 2014 22:28
I guess that's how it works - the handlebars template looks for a partials.weather object
the server sets res.locals.partials.weather to getWeatherData()
so all of this happens on the server side before it's sent to the browser i think
ooooooo, i'm using express 4 with the express 3 handlebars
(let me sort that out)
Dale Corns
@dcorns
Oct 28 2014 22:31
This is an angular call $http.put('api/v_0_0_1/users/' + user._id, user)
.success(function(data) {
$scope.getAllUsers();
})
Robert Talamantez
@Talamantez
Oct 28 2014 22:32
maybe i should just switch to angular right now :-D
Dale Corns
@dcorns
Oct 28 2014 22:32
it is an http.put but the same kind of thing would hold for a get
no I dont think so
are you just using express without a framework?
I like that better, hold on a sec
Robert Talamantez
@Talamantez
Oct 28 2014 22:33
ya -trying a pared-down method
node, express, hbs
Dale Corns
@dcorns
Oct 28 2014 22:35
Let me take a quick look at my raw express code...Its a restful architecture right?
Robert Talamantez
@Talamantez
Oct 28 2014 22:35
ya
Dale Corns
@dcorns
Oct 28 2014 22:41
Sorry dude, but I slept for a half hour last night and I'm running a little slow, and have so many projects in my dir that I cant find the example I was looking for. What is the script you have running on the client side?
Robert Talamantez
@Talamantez
Oct 28 2014 22:42
hey man, it's cool - let me sort out this dependency issue - I'll set up a repo and link you when i've got it sorted out
thanks again man
Dale Corns
@dcorns
Oct 28 2014 22:45
ok, I dont think it is the template, more than likely it is the restful that is the issue. You should at least be getting the res object back. Take a look at the network part of dev tools and do a refresh, that may help also.
Robert Talamantez
@Talamantez
Oct 28 2014 22:46
ok cool
Dale Corns
@dcorns
Oct 28 2014 22:46
good chating with you, Im sure you will figure it out.
Robert Talamantez
@Talamantez
Oct 28 2014 22:46
thanks man - good to chat too - i'm sure i'll be back about it lol