Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can this template be set up so that each article is it's own file? #308

Open
rchrdnsh opened this issue Aug 23, 2016 · 3 comments
Open

Can this template be set up so that each article is it's own file? #308

rchrdnsh opened this issue Aug 23, 2016 · 3 comments

Comments

@rchrdnsh
Copy link

I noticed that this blog template is set up so that all articles are 1 large JSON file, but I would like to figure out how to set up the template so that each article is in it's own JSON file, but I'm not sure how to go about it. It would be awesome if the template was set up this way, so I could see and understand how to achieve this structure.

This is just a feature request, really :-)

Anyway, thanks :-)

@Zippersk
Copy link

Zippersk commented Sep 4, 2016

I don't understand why you want this but here you go...
Article detail element has "article" object property. There goes article data.
<article-detail name="detail" article="[[article]]"></article-detail>

Let's say you got you article's data named like this: art1.json art2.json ... artXX.json. Than you could load it with iron-ajax

<dom-module id="your-element">
    <template>
        <iron-ajax id="ajax" handle-as="json" on-response="handleResponse"></iron-ajax>
        <template is="dom-repeat" items="{{articles}}">
             <article-detail name="detail" article="{{item}}"></article-detail>`
        </template>
    </template>
<script>
    Polymer({
        is: 'your-element',
        properties: {
            articles: {
                type: Array,
                value: function () {
                    return [];
                }
            },
            i: {
                type: Number,
                value: 0
            }
        },
        ready: function: () {
                this.$.ajax.url = "art" + this.i + ".json";
                this.$.ajax.generateRequest();
        },
        handleResponse: function (e) {
                var article = e.detail.response;
                this.push('articles', article);
                this.i++;
                this.$.ajax.url = "art" + this.i + ".json";
                this.$.ajax.generateRequest();
        }
    });
</script>
</dom-module>

But don't do this. Posts data are usually small. Each article will needs one request to server.

@jsilvermist
Copy link

If the data is too large to download all at once, would it not be better to store all the data in a single json file, and then send an Ajax request to a php script which pulls in only the parts you want all at once, instead of forcing yourself to generate a new request per post?

@Zippersk
Copy link

Zippersk commented Sep 4, 2016

Yeaaah, that's called api. PHP should do all work for you. For example reddit has great api where you can filter and sort articles.
https://www.reddit.com/search.json?q=polymer&limit=10

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

No branches or pull requests

4 participants