This may very well be a problem with my implementation of the API. I'm currently just trying to make every variable get replaced with a single string ("TEST VARIABLE"). Seems like it should be pretty straightforward.
<article class="post">
<header class="post-header">
<h1><a href="{{url}}" title="[Permalink] {{title}}">{{title}}</a></h1>
<span class="date">{{date}}</span>
</header>
<section class="post-content">
{{content}}
</section>
<p class="continue-reading"><a href="{{url}}">Continue reading »</a></p>
</article>
int TriboCrustacheGetVariable(crustache_var *variable, void *context, const char *key, size_t keySize) {
printf("Get variable: %s.\n", strndup(key, keySize));
variable->type = CRUSTACHE_VAR_STR;
variable->data = (void *)"TEST VAR";
variable->size = sizeof("TEST VAR");
return 0;
}
crustache_template *pageTemplate;
crustache_new(&pageTemplate, &api, buffer, length);
struct buf *outputBuffer = bufnew(128);
crustache_var context = {
.type = CRUSTACHE_VAR_CONTEXT
};
int error = crustache_render(outputBuffer, pageTemplate, &context);
if (error) {
printf("Render error: %s\n", crustache_strerror(error));
}
printf("\nOutput data:\n%s\n", outputBuffer->data);
bufrelease(outputBuffer);
Get variable: url.
Get variable: title.
Get variable: title.
Get variable: date.
Get variable: content.
Get variable: url.
Output data:
<article class="post">
<header class="post-header">
<h1><a href="TEST VAR
So the get variable function gets called the right number of times, but for some reason the output only continues until the first variable. Any idea what is going wrong?