Hi,
I know maybe I’m asking too much, but - as the tag say, that’s my first time with this functions. I’d like to build a simple plugin who takes infos from an SQLite database and put the infos somewhere in my templates.
I’m not talking about something specifical like the SQLite plugin (who works with shortcodes), but just a way to take the string or the integer from the database and putting that somewhere in the page or outside the page (footer, sidebar…).
How can I do that?
I know I should use PDO functions, but I don’t know how.
Thank you all, great community as always.
The SQLite plugin shows you the basics of accessing the data: see lines 8, 47, 48, 119–138.
Then all you do is inject that data into twig variables. That’s usually done via $this->grav['twig']->twig_vars[XXX]
, as I do in my Blogroll plugin. You can then access that data in your templates.
First of all: thank you for the accurate answer.
I’m not used to php, so I have a hard time in exploring other’s code.
I’m gonna try to build my own plugin following your instructions. If I will find some problem wich I can’t solve, maybe I write again. Otherwise I’ll post my results and reflections and close the topic in the next days.
Thanks again
I tried many times, but I can’t run your plugin blogroll properly. I was trying because I thought I could learn from how blogroll works, but I really don’t know why (with original yaml file) it doesn’t work on quark theme. I tried disabling css, changing tags and links but nothing. Any ideas on why it doesn’t work?
What do you mean by “doesn’t work”? I’d have to see your config files and twig.
It means that I include the blogroll.html.twig file in the sidebar template exactly like you suggest in the readme (copypasting) but, without touching the config files, it show me only the “SIDE PROJECTS” h2 in the sidebar.
I tried with my edited quark theme, with an old quark theme and with a fresh new version of grav exactly like it’s released in the landing page.
So, with a full default version of grav + quark theme, with the fully default plugin I can’t see a list. I really didn’t touch anything in the settings to make things easy.
The sample code uses the tag projects
, but in the default config, there’s no such tag. Try using tag1
or tag2
. I should change that in the README.
Oh, that’s true! I was searching the problem in the php and I didn’t noticed that the error was in the template. It makes perfect sense. Thanks