Originally posted by @Adam.Wilson:
For Treehouse meeting #4, here is the “BC Blog to Treepl Migration” code snippet if interested.
Any questions and/or feedback most welcome.
{% comment -%}
NOTES:
- Adjust ASSIGNs (Liquid variables) below with your values.
- Light grey columns are hard coded values for Treepl import
- If using Authors, set up the Authors in Treepl first and note their system IDs;
Then find and replace Author names with corresponding Treepl Author IDs when in your spreadsheet. (as we need to import with ID values only)
- If over 500 posts? batch collection with skip/limit as needed.
{% endcomment -%}
{% assign BCblogID = 4989 %}
{% assign TreeplTemplateID = 1815 %}
{module_data resource="blogs" version="v3" fields="id,siteId,blogId,postTitle,postFeaturedImage,postBody,createBy,releaseDate,blog,author,enabled" subresource="posts" resourceId="{{BCblogID}}" skip="0" limit="500" order="-releaseDate" collection="posts"}
<table border="1">
<thead>
<tr>
<th>External ID</th>
<th>Item Name</th>
<th>Item Description</th>
<th>Release Date</th>
<th style="background:lightgray;">Expiry Date</th>
<th style="background:lightgray;">Weight</th>
<th style="background:lightgray;">Template ID</th>
<th>Enabled</th>
<th>Classifications</th>
<th>Item Tags</th>
<th style="background:lightgray;">Created By Member Id</th>
<th style="background:pink;">Author</th>
<th>Image</th>
</tr>
</thead>
<tbody>
{% for p in posts.items %}
<tr>
<td>{{p.id}}</td>
<td>{{p.postTitle}}</td>
<td>{{p.postBody | escape}}</td>
<td>{{p.releaseDate | date: "%M\/%d\/yyyy"}}</td>
<td style="background:lightgray;">1/1/2099</td>
<td style="background:lightgray;">0</td>
<td style="background:lightgray;">{{TreeplTemplateID}}</td>
<td>{{p.enabled}}</td>
<td>
{module_data resource="blogposts" version="v3" fields="category" subresource="categories" resourceId="{{p.id}}" skip="0" limit="100" order="objectType" collection="postCats"}
{% if postCats.totalItemsCount > 0 -%}
{% for i in postCats.items -%}{{i.category.category}}{% if forloop.last -%}{% else -%},{% endif -%}{% endfor -%}
{% endif -%}
</td>
<td>
{module_data resource="blogposts" version="v3" fields="tag" subresource="tags" resourceId="{{p.id}}" skip="0" limit="100" order="objectType" collection="postTags"}
{% if postTags.totalItemsCount > 0 -%}
{% for i in postTags.items -%}{{i.tag.tagName}}{% if forloop.last -%}{% else -%},{% endif -%}{% endfor -%}
{% endif -%}
</td>
<td style="background:lightgray;">0</td>
<td style="background:pink;">{{p.author.firstName}} {{p.author.lastName}}</td>
<td>{{p.postFeaturedImage}}</td>
</tr>
{% endfor %}
</tbody>
</table>