Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Distill
Arg! False victory. In my excitement to see the build happen, I overlooked that the authors/affils and figure blocks don’t even show up at all. So there must be something wrong with the way I’ve done that.
Frankly, this yaml and liquid shite seems way too touchy and confusing to be worth a damn. I’m ready to go back to HTML and say, ‘if we don’t need a figure in this one, just delete the block for it. It should not be this hard to add an include and use it in combination with front matter.
Also, after looking at various resources, some of which you’ve pointed out, Bloke, I can say that any help site that based its examples on yaml/liquid/html patterns would be very popular. Everything is just the yaml, or liquid, but not all three together, which is what is needed to make sense of it. I guess the world of GitHub/Jekyll doesn’t count on HTML noobs messing in a repo. Or YAML/Liquid noobs like me trying to build a site.
</rant>
Offline
Re: Distill
Just got this from GitHub (after I complained):
Rendering Liquid: user-story.md
Liquid Exception: Invalid syntax for include tag. File contains invalid characters or sequences: authors.html ref=”“ Valid syntax: {% include file.ext param=‘value’ param2=‘value’ %} in user-story.md
Fatal: ArgumentError
Invalid syntax for include tag. File contains invalid characters or sequences: authors.html ref=”“ Valid syntax: {% include file.ext param=‘value’ param2=‘value’ %}
The file is now called writers.html (not authors.html), so I’m not sure they actually tested against the current structure-state or not.
But it appears the problem — or at least the first instance of one — was in the include tag. Whether it was how I had it wrong before, or with defining the local variable, I don’t know. But I know neither way works as I had it.
Now we go back to my gripe again, because even though they give me this valid syntax pattern…
{% include file.ext param='value' param2='value' %}
I don’t know how to use it for a hash/array.
For example, if my front matter is this:
yaml
collaborators:
-
who: "Jane Doe"
affiliation: "That Place"
affiliation_url: "https://domain.tld"
-
who: "John Updike"
affiliation: "The Other Spot"
affiliation_url: "https://domain.eek"
Then instead of this…
{% include writers.html authors_info=page.collaborators %}
How do I structure it? What if there were 10 collaborators on a given definition? How does that impact building the include tag?
And then what should the markup look like in the include content?
So you see, a yaml/liquid/markup pattern library is really needed. Maybe that should be a new repo, if I could figure this crap out.
They also tell me I should install Jekyll locally and test that way so I suffer with it on my own. I knew that would be the inevitable end.
Offline
Re: Distill
Hmmm, I’m not familiar enough with Jekyll and don’t have it locally so I’m kind of shooting blind. But I guess there are a few things at play here.
Firstly, are you sure your frontmatter syntax is correct? If you try to pass something that isn’t a proper structure to an include, it will probably throw that error you’re seeing because it thinks you’re passing junk into the include. This resource might help as it gives a fairly complex example that you might be able to glean something from and pare down to your uses.
Secondly, your include syntax looks okay, but I can’t tell from the (many) conflicting sources on the web what the actual syntax is for passing variables in. Presumably there are a few flavours, either now or in the past that may have changed over time. As far as I can tell, you can:
{% include writers.html myvar='Some static text' %}
and you’d access that in your writers.html
like this: {{include.myvar}}
, which would just print out Some static text
.
Then we have:
{% include writers.html myvar=page.collaborators %}
or
{% include writers.html myvar={{page.collaborators}} %}
I’m not sure which is correct as I’ve seen both in examples on the internet.
Either way, if your collaborators is a valid structure, you should be able to access those in writers.html
like this:
{% for loopvar in include.myvar %}
// now each value in your structure is available via loopvar.name
// e.g. {{loopvar.who}}
// {{loopvar.affiliation}}
// etc
{% endfor %}
You can call loopvar
anything you like and use it inside the for...endfor
to access the variables in your structure.
This is just one of those frustrating situations where you need to start small and build up, changing only one thing at a time until it breaks, figure that out, then move on. Welcome to the murky world of programming ;-)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Distill
It seems the place where things are tripping up is with the liquid structure in the include file (function?) markup.
I’m working with just the Figure for now, because that’s a simpler/fixed front matter hash with 3 keys. It will never be more, as opposed to the situation with authors, which could keep growing, so I think each function will need a different liquid structure, yes?
If I edit the figure.html markup to straight HTML (no liquid), it outputs with no build or display problems using this function call:
{% if page.figure %}
{% include figure.html figure_info=page.figure %}
{% endif %}
The local variable isn’t used for anything, of course, but it at least confirms the pattern is written correctly.
But whether I need to use a variable (myvar=newvariable
) or a parameter string (param="value"
) or both, I don’t know, because I’m having trouble getting my head around the liquid needed in the function markup first.
Here’s the figure function without any liquid (this passes without problems)
<figure>
<img alt="A placeholder image." src="http://content-strategy-forum.github.io/csf-glossary/assets/images/placeholder.png">
<figcaption>A belle figure of mysterious nature.</figcaption>
</figure>
The front matter:
yaml
figure:
fig_slug: placeholder
fig_alt: "A placeholder image."
fig_caption: "A belle figure of mysterious nature."
Now, how to dress up the markup with Liquid to grab those three values? This is the part I can’t get my head around. That tutorial says:
You cannot return an “array” or any other variable than a string. If you need to do so, then convert the variable into some string format that you can then capture and reconvert into variable in the caller.
Unfortunately, that lingo makes no sense to me.
I’ve been testing with just the figure caption to isolate one spot.
The key values in the figure function do qualify as strings, I think, so I tried this:
{% if page.figure %}
{% include figure.html figslug="figure_slug" figalt="fig_alt" figcap="fig_caption" %}
{% endif %}
And that did output a caption (the test key), but the value was “fig_caption”, not the key value is in the front matter. I figured that would be an easy win, but hell no.
Then I thought, ‘Wait! is the figure front matter variable supposed to be its own front matter in the figure function file? Test says: Nope.
So I’ve got no clue, except to say, screw this. I’m going back to good ol’ HTML. Collaborators be damned. I need someone smarter than me doing the yaml and liquid on this project if it’s going to happen at all.
Offline
Re: Distill
What happens if you do this?
{% if page.figure %}
{% include figure.html figslug="figure_slug" figalt="fig_alt" figcap=page.fig_caption %}
{% endif %}
or this:
{% if page.figure %}
{% include figure.html figslug="figure_slug" figalt="fig_alt" figcap={{page.fig_caption}} %}
{% endif %}
Does your frontmatter figure caption get output then?
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Distill
This first one builds but there’s no output.
The second one throws a build error, so that’s probably not allowed structure.
This is all I have in the markup: <figcaption>{{ include.figcap }}</figcaption>
. Could be the problem. I don’t know.
Don’t waste anymore time on it, brother. I’ve spent hours and hours and hours this week on it. It’s f-ing ridiculous. I will never do another Jekyll site. I’ve got better things to do, like spring yard work.
By the way, I’ve started issues for these, which might be a better place to throw down at this point:
Offline
Re: Distill
Destry wrote #305171:
Managed to get these figured out with a little help from the Jekyll community. It was far easier than I was fighting with. You may see the explanations in the two issues per links above.
The one for authors/affils even shows a bonus alternative method where a new YAML data file is used to centralize data for all contributors on the project:
---
jim_jones:
who: "Jim Jones"
affiliation: "Jim Jones & Bros."
affiliation_url: "url"
jane_doe:
who: "Jane Doe"
affiliation: "JD Shop"
affiliation_url: "url"
etc:
Then in the local .md file you simply call the relevant authors with an adjusted front matter variable:
---
collaborators: [jim_jones, don_dealio, et_cetera, ...]
Managers can maintain the data file. Authors can add their juice to the collaborators
variable in the local .md file in a way that’s even less likely for them to screw up. ;)
And I should be able to use the centralize data to create a wrapping list of contributor names on the index page too, though I’ve not figured the markup for that just yet. But anyway.
Offline