Let's move to more complex example and learn how to make a blog using APIQ CMS. Let's skip APIQ (and APIQ Models extension) installation steps and consider we already have blank CMS installation. By following steps below, you'll get fully functional blog.
First, you need to have HTML either downloaded or prepared from scratch by HTML coder. I picked this one:
Ok, in downloaded template archive I have index.html
. I'm going to use it as a template for blog index page.
Just paste html content, give template a name, and click "Add template".
Now we need to upload all assets (under "Assets" section) we have in downloaded template, i.e. images, stylesheets and javascripts.
You could select multiple at once. For my template, I uploaded js
folder content first, then fonts
, images
and css
.
Now we need to fix fonts URLs (like url("../fonts/icomoon/icomoon.eot")
) or other URLs in our stylesheets by inserting correct URLs from "Assets" section.
Next, let's find in template's content a place where page content should be injected and insert there special Liquor instruction {% yield %}
. I'm going to insert it after <div id="gtco-main"><div class="container">
and remove all content until closing tags.
Now let's create index page that uses just created template and paste there the content we've cut earlier from template. Once we have this in place, you should see something like this at website's root:
Next I'm going to make index page dynamic by introducing some models. First, I want main menu (Develop
, Business
and etc.) to represent blog categories. Let's create Category
model under APIQ Models
section.
Now let's output categories as menu snippet. I extracted <ul>...</ul>
from template into new snippet with "Menu" name and "menu" slug, and included this snippet in template with:
And finally, I modified snippet like this (name
is the only property I added to Category
model, permalink
is built-in property):
Ok, I can add categories and have dynamic menu based on them. Let's add second model - Post
- and set up relationship between it and Category
model.
After this, I added one post belonging to "Development" category. Now I'm going to show the latest post as wide banner (as suggested by template design). I updated template's content like this (notice how I fetched the most recent post ):
And now, below this header I'd like to list all posts. This is the only content of index page for this purpose:
Index page should look like this (isn't it cool?).
This is our final step: we want to have category page and post page so our permalink
properties will start working and point to concrete category or post. Let's create these 2 pages as children of index page. The most tricky thing here is to enable Use as object template
property and choose representable object.
Don't forget to put some html displaying Category and Product in corresponding pages. In these pages you have access to current object via item
object. I.e. you could output post's content like this (on Post page):
On Category page there's one more trick for fetching current category's posts (because I used belongs to
field):
And that's it - now I have completely dynamic and working Category page and Product page! And that's all for this tutorial: we have pretty basic blog functionality with a lot of possibilities to improve it further. For example, you might add Published
field to Post
model and list only published posts by default, or maybe introduce posts tagging. Your imagination is the only limit, so just try it ;-)
You could find my final result at: http://patient-forest-605.app.apiq.io