This is just a quick question to make sure the situation hasn’t changed with Kirby 4, as I’ve seen other posts that make me believe it certainly wasn’t possible before.
I’m trying to get an info field to pull in the url of the page being edited. A bit like this:
opengraphimagepreview:
type: info
text: "(image: {{ page.url }}.png )"
(Specifically, I’m using something like this Cookbook recipe to create open graph images, and I want to be able to show the user what the image looks like. An info field seems the best way to do this. But also I can imagine other uses for interpolating dynamic content into an info field like this.)
Am I right in thinking that info fields don’t allow for dynamic content to be included, and I’ll have to figure out a way to amend the field/create a custom field?
Thanks!
I think this has always worked since Kirby 3.0.0.
You might want to give the image a width though, otherwise it will shrink to 0 in the info container (becoming essentially invisible).
fields:
opengraphimagepreview:
type: info
text: "(image: {{ page.url }}.png width: 1200)"
1 Like
OH! It does seem to work! (And doesn’t seem to shrink if it hasn’t been given a width.) What was I up to before? I must have done something to muddle myself. Thank you!
I think the limitation is that the query result (the stuff between {{
and }}
) can’t be HTML, because it would be escaped.
So,
text: "(image: {{ page.image.url }})"
works, but
text: "{{ page.image }}"
doesn’t, because it produces something like
<img alt="" src="...">
1 Like
That seems correct to me (and happily isn’t an issue for what I want to do, I don’t think).
Although I’ve now hit another issue: I want to show the contents of a writer field but with the html tags (strong, em, links etc.) removed.
This outputs with all the html tags:
text: "{{ page.text }}"
I can get rid of the block level tags with:
text: "{{ page.text.kt.inline }}"
But I can’t seem to find a way to strip out the rest of the html tags…
You’d need a field method to strip HTML tags from a field.
You can either write that in your own plugin, or abuse excerpt
:
text: "{{ page.text.excerpt() }}"
It’s not documented, but using excerpt()
without a maximum length just strips the html tags and doesn’t cut the string to a specific length.
1 Like
I would love to say that I’ll take the opportunity for self-improvement and write my own plugin, but excerpt seems to work perfectly for this, so I’m going to take the lazy route. Thanks so much!