I'm trying to use the Polymer expressions to show certain things.
I have a .php
file that prints out a json_encoded array of for example names. Now there's 3 possibilities the way I see it:
- The list of names gets returned properly
- There are no names found in a database, so
null
or something is printed - An error occured in the php file
So depending on what gets returned, I'd like to display the correcy message.
This can be done using <template if="{{conditionalValue}}">
. This is what I have:
<template if="{{people != null}}">
<template repeat="{{person in people}}">
<name-card name="{{person.name}}">
</album-card>
</template>
</template>
<template if="{{people == null}}">
<div>There are no people listed.</div>
</template>
This doesn't seem to work. When the .php
file returns a list, the top templates both get executed and I get a whole list of <name-card>
elements. However, when in the php file I do echo json_encode(null)
for testing measures, nothing displays at all. So I must be doing something wrong with my conditionalValue. How do I test whether this is an array with elements in it?
Also, is there a way to test for non-json content, in case of an error on the php script?