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
include php file in my ,md #489
Comments
|
Short answer: You can't. On purpose. Anyway, Pico comes with a very powerful plugin system to do what you want. Just create a simple Pico plugin (create <?php
class PicoUberGallery extends AbstractPicoPlugin
{
public function __construct(Pico $pico)
{
parent::__construct($pico);
require_once('/home/user/public_html/ubergallery/resources/UberGallery.php');
}
public function onTwigRegistered(Twig_Environment &$twig)
{
$twig->addFunction(new Twig_SimpleFunction('gallery', function ($name) {
return UberGallery::init()->createGallery($name);
}));
}
}You can then use it in your Twig templates (e.g. {{ gallery("2019_NZ") }} |
|
Thanks!
…but does that mean I cannot call the plugin directly from my .md file? I ask because I was imagining a .md for each gallery that could use the same plugin.
Cheers,
James.
On 9 Mar 2019, at 19:33, Daniel Rudolf <notifications@github.com> wrote:
Short answer: You can't. On purpose.
Anyway, Pico comes with a very powerful plugin system to do what you want. Just create a simple Pico plugin (create plugins/PicoUberGallery.php with the following contents) and utilize a Twig function:
<?php
class PicoUberGallery extends AbstractPicoPlugin
{
public function __construct(Pico $pico)
{
parent::__construct($pico);
require_once('/home/user/public_html/ubergallery/resources/UberGallery.php');
}
public function onTwigRegistered(Twig_Environment &$twig)
{
$twig->addFunction(new Twig_SimpleFunction('gallery', function ($name) {
return UberGallery::init()->createGallery($name);
}));
}
}
You can then use it in your Twig templates (e.g. themes/my_theme/index.twig) using:
{{ gallery("2019_NZ") }}
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#489 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AhCiwDi9VZ5WKobnWywOYu7G5Ib0uBLbks5vVAyfgaJpZM4bmsh7>.
|
|
No, you can't call this in your content files. Pico isn't different to virtually any other CMS here, the concept behind is called "separation of concerns". Your content files are supposed to define your contents, not the layout/structure of your website. This is up to your theme. Anyway, naturally you can still use the same template and plugin for any gallery on your website. Simply replace the currently static ---
title: This is my 2019 NZ Gallery
gallery: 2019_NZ
---And use this snippet in your Twig templates (e.g. {% if meta.gallery %}
{{ gallery(meta.gallery) }}
{% endif %}See http://picocms.org/docs/#text-file-markup and http://picocms.org/docs/#themes |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! 👍 |
|
Hi, What I want to do is to include a php file which printing / output a list of links via a function. But I don't understand how Class work :(. Can you give me pointers please? |
|
This highly depends on the actual code you're trying to include resp. what code you're trying to "include". If you're just trying to call some function, see #489 (comment) - the PHP file with the function definition is included on line 7, the function is later called on line 13. |
|
Hi, I make a RandomLinks.php inside the Plugin dir `<?php } For testing, I just do echo inside the function printRandomLinks()
then I call |
|
|
|
Hi, Ah, a noob mistake lol. Ok, so I tried to call the function but got this error : Something wrong that it failed to add the linkslist function to twig? I'm sorry if I wasn't very clear because of my lack of knowledge. I want to pass the result from printRandomLinks() to twig. I thought Twig_SimpleFunction() is the way to go, but I don't know how it works. |
|
Let's say my plugin code become like this: class RandomLinks extends AbstractPicoPlugin calling |
|
The <?php
class RandomLinks extends AbstractPicoPlugin
{
const API_VERSION = 2;
public function printRandomLinks($links)
{
$links = "<h1>The Links</h1>";
echo $links;
}
public function onTwigRegistered(Twig_Environment &$twig)
{
$twig->addFunction(new Twig_SimpleFunction('linkslist', function ($links) {
return $this->printRandomLinks($links);
}));
}
} |
|
It says : |
|
Works for me. Make sure to put it below btw: You should |
|
Yes! Thank you soooo much... For being patient with a noob like me. My mistake was: I don't put the plugin file in its own folder. Thank you again! I really like Pico! God bless you! |
Hi,
Very new to all of this. I cam trying to move from another .html based website to pico.
I was using a script called Ubergallery (and still want to). I called in in my .html file as follows:
<?php include_once('/home/user/public_html/ubergallery/resources/UberGallery.php'); $gallery = UberGallery::init()->createGallery('2019_NZ'); ?>How do I do this in my .md file?
The text was updated successfully, but these errors were encountered: