Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn arrays/lists into strings #202

Closed
Lulullia opened this issue May 10, 2021 · 9 comments
Closed

Turn arrays/lists into strings #202

Lulullia opened this issue May 10, 2021 · 9 comments

Comments

@Lulullia
Copy link

@Lulullia Lulullia commented May 10, 2021

Hi, this is something I've been trying to solve myself but with no luck.

I have a table view that displays the tags of the query-ed files, but since I have lots of them, I feel like it's a waste of space to use bullet lists for tags.

image

Instead I just want to render the tags in a single line, not in a bulleted list format, this way:

image
(this is a manually-created table, looks much better)

I searched but didn't find any functions who could help.

A possible solution would be to add a simple function that turns arrays into string, with an optional argument for the separator? Something like :
str(array, " ")

@Moonbase59
Copy link

@Moonbase59 Moonbase59 commented May 15, 2021

If using dataviewjs, this is easily done. For example, in the map, instead of:

p.file.etags

simply use

p.file.etags.join(' ')

Result looks like this:

obsidian-dataview-join-tags

@Lulullia
Copy link
Author

@Lulullia Lulullia commented May 15, 2021

Thanks, I'll have to translate my whole query in JS but I guess it's better than nothing^^

@Moonbase59
Copy link

@Moonbase59 Moonbase59 commented May 16, 2021

Yeah, I was hesitant, too, at first. But probably worth checking out—you can do many wonderful and useful things with DataviewJS.

@Lulullia
Copy link
Author

@Lulullia Lulullia commented May 17, 2021

I know haha, the more code-ish it gets, the more freedom you have. Thanks for the help btw, it's resolved now, but I don't know if I should close this or not since this is still only a workaround?

@blacksmithgu
Copy link
Owner

@blacksmithgu blacksmithgu commented May 18, 2021

I've added the join(list, [separator]) function to dataview which converts a list into a single line; if you use join(<list>), it will separate by spaces by default.

@blacksmithgu
Copy link
Owner

@blacksmithgu blacksmithgu commented May 18, 2021

Fixed for real in release 0.3.8.

@filmgal
Copy link
Sponsor

@filmgal filmgal commented Jun 1, 2021

join(list, [separator])

@blacksmithgu Thanks for that! Is this for dataview or dataviewjs? If the former, any chance of including an example of use in the docs, specifically how and where it would go in our list or table queries? I've had no luck implementing it in either.

@ryanpcmcquen
Copy link
Contributor

@ryanpcmcquen ryanpcmcquen commented Jun 2, 2021

It works like this (dataview):

Table join(file.outlinks, ", ") as Connections
From [[Foo]]

Which I used to write in dataviewjs as this (before finding out about join() being added):

dv.table(
    ['File', 'Connections'],
    dv.pages('[[Foo]]').map((page) => {
        return [
            `[[${page.file.name}]]`,
            page.file.outlinks
                .map((link) => {
                    return `[[${link.path.replace(/\.md$/, '')}]]`;
                })
                .join(', ')
        ];
    })
);

@filmgal
Copy link
Sponsor

@filmgal filmgal commented Jun 4, 2021

@ryanpcmcquen Thanks for taking the time to respond. I appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants