Good people.
I am creating my first theme. I have not yet created a website yet. I am learning as I go. I do intent to use Publii for several sites, but want to have my own themes using CoffeeCup Site Designer.
I created a theme by obliterating the technews theme and get the following error when rendering “Preview your changes”
Rendering process failed
An error occurred during rendering process:
Unexpected identifier
I did try to create a custom helper, isEven, and put it in helpers.js. Here is the code.
/*
* Custom theme helpers for Handlebars.js
*/
let themeHelpers = {
getTagColor: function(tag, tagsConfig = '') {
if(tagsConfig.trim() === '') {
return 'u-tag--1';
}
tagsConfig = tagsConfig.split(',');
if(tagsConfig.length) {
tagsConfig = tagsConfig.map(item => item.split('='));
for(let tagConfig of tagsConfig) {
if(tagConfig.length !== 2) {
continue;
}
if(tagConfig[0].trim() === tag) {
return 'u-tag--' + tagConfig[1];
}
}
} else {
return 'u-tag--1';
}
return 'u-tag--1';
}
isEven: function(value, options) {
if (value % 2 == 0) {
return true;
} else {
return false;
}
}
};
module.exports = themeHelpers;
Here is how I am using it in Handlebars (index.hbs).
{{#each posts}}
{{#isEven @index}}
<h3 class="article-heading">{{title}}</h3>
<p class="paragraph body-copy">{{{text}}}</p>
<picture>
</picture>
{{else}}
<picture>
</picture>
<h3 class="article-heading">{{title}}</h3>
<p class="paragraph body-copy">{{{text}}}</p>
{{/isEven}}
{{#if @last}}
{{else}}
<hr>
{{/if}}
{{/each}}
All the rest of the modifications to the theme come directly from your website — so this is only the tricky part.