Hi, I have a problem, I need every time type tag on each project…
what I mean - can I just add already created tag?
for example: I start typing - des
- and it shows design
or something else that already added in other posts?
P.S KirbyCMS 3
Hi, I have a problem, I need every time type tag on each project…
what I mean - can I just add already created tag?
for example: I start typing - des
- and it shows design
or something else that already added in other posts?
P.S KirbyCMS 3
For autocompletion to work, you have to set the options attribute, either fixed or dynamic options via query. Check out thetags field documentation.
I’d also be interested in this and would suggest adding such an example it to the docs.
In Kirby 2 we had index: siblings
and index: template
. In Kirby 3 we will have to do some kind of query with ->pluck()
?
Yes, since this is the second question in two days re tags autocompletion, I’ll make this more explicit in the docs (tomorrow probably, because tonight, I have to get the next Kosmos edition ready to go out tomorrow).
I was looking for this as well and this seems to work for existing tags:
tags:
type: tags
label: tags
options: query
query: page.siblings.pluck("tags", ",", true)
The first argument is the field name, the second one is the separator, and the third one sets uniqueness.
@texnixe: I’m always lost at first because I’d expect the function to be called split
and not pluck
(you pluck a goose but a string?). Also I just noticed that the query syntax requires double quote in order to recognise the spliting character.
Both split()
and pluck()
exist.
Use split()
for tags (etc.) in a single page/file etc. (it’s a field method)
Use pluck()
for tags in a collection. pluck()
loops through all pages/files etc. in the collection and fetches all the tags (it’s a collection method)
Yes, for the query language it’s safer to use double-quotes in general, single quotes work most of the time, but not always. I have already created an issue for that in the docs repo.
So would it be possible to use query: page.siblings.tags.split(",")
? This would be an obvious syntax to me but I thought that doesn’t work for some reasons.
No, because you can’t call tags()
on a collection.
But if you can’t get used to it, you can create a custom split()
pages method that does exactly what the pluck()
method does and be happy ever after
Aah, right that makes sense from the programming side of things.
Still I find this very hard to remember and distinguish from the user’s point of view.
(I will learn it over time, of course, so just saying …)
See my edited reply.
Haha, okay, I didn’t notice that. If I’m able to create a custom page method I should be able to learn what pluck
means
Ah, come on, you have created a plugin, then you can also create custom methods.
<sheepish>
Yes, I actually created custom methods already</sheepish>
.
Still, pluck …
split()
just wouldn’t be right from a semantic point of view, actually. While splitting might be involved in the plucking (in the case of a field with a comma or whatever separated list), it will not necessarily be the case, e.g. if you just pluck single values from a field.