Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Table-import manipulation

Started by Shane 7 years ago · 7 replies · 952 views
7 years ago

I installed the Table-Importer plugin, and got it to pull the data in correctly. I would love to use a 'if then" statement to condition the data I pull in from the csv file. Basically, I'm using the csv file as a simple database. If column1 = this text, then display column2. That is the basic usage that I want to do. This will enable me to build a large webpage quickly. I know I can enable twig in the front matter... however I'm not sure how to get twig to reference the csv file. Any help, or links to get me pointed in the right direction would be greatly appreciated. Twig syntax really resembles a lot of liquid syntax in Jekyll Static Site generator. I don't know either language, but it is fairly easy to read and decipher.

Shane

7 years ago

The Table Importer plugin is too specific. It is designed only to build HTML tables from various input files. You need something more generic. I also have the basic Import plugin (GitHub is apparently having difficulties today, but the repo is there). But you'd still have to do a fair bit of work in Twig.

Also, see the plugins page and search for "data" or something like that for other database solutions.

7 years ago

Thanks for the tip. I actually was looking at modifying the php code on your plugin to have it use the conditional statement based on front matter in the page to determine what to display on the page.... still thinking about that idea.

Shane

7 years ago

I installed the import plugin, because I think you may be right, that should work better. It will allow me the flexibility. I cannot get that plugin to import the document. I put the import: filename.yaml in the frontmatter of the page I want to import it to, and I get this error:

0 - Argument 1 passed to Symfony\Component\Yaml\Yaml::parse() must be of the type string, null given, called in /Users/username/Sites/gravtest/user/plugins/import/import.php on line 36

My frontmatter looks like this:

imports: 'data:filename.yaml'

It did occur to me that perhaps this doesn't belong in the front matter... but I'm not sure where to put it. Perhaps in the page template setup? Hopefully you can point me in the right direction on this. Thanks!

Shane

7 years ago

The docs will show you your error. It needs to be imports: 'user://data/filename.yaml'

👍 1
7 years ago

Thanks! The README file needs updated, as I was just grabbing the usage off of that. It says,

By default, the plugin looks for files in the same folder as the page itself. But you can prefix filenames with data: to anchor your search in the user/data folder.

And the Example it gives is:

imports:

  • 'file1.yaml'
    • 'data:file2.json'

At any rate, I got that fixed, and that indeed fixed the problem. Thanks! Now I can move on to bigger things, and work on pulling the data out I want.

7 years ago

Doh! Sorry about that! I must have copied that from some other plugin. I'll fix that as soon as I can.

7 years ago

Not a problem. I'm struggling with usage too. I found this old post: /forum/plugins/correct-usage-of-import-plugin-t5897. When I try to implement the same usage... nothing shows on the page. I do have twig enabled. I will have to tinker with this later though.

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 51 8 hours ago
Support · by Anna, 2 days ago
2 58 10 hours ago
Support · by Justin Young, 11 hours ago
1 30 11 hours ago
Support · by Duc , 1 week ago
2 63 5 days ago
Support · by Colin Hume, 1 week ago
2 55 5 days ago