Hej together … iam searching for an how-to for include / insert external (same server) php scripts.
Iam a beginner in php and the kerby core is a bit difficult to understand. (ofcourse just for me)
Hope there is a how-to cause i dont want to use another cms.
thx in advance … so long Stoffex
What exactly do you mean by external? Do you want Kirby to load a script automatically? Do you want to call a script that is located anywhere on the server? And what exactly do you want to achieve?
All scripts that you put into /site/plugins are loaded automatically.
1 Like
Thx for the reply …
I want to insert a booking script and a form mailer.
But i dont understand how i can call them up like include(); i guess it is with kerby a bit different.
/site/plugins/your-plugin/your-plugin.php
…will load on Kirby init. Make sure folder name and filename match, like above.
1 Like
Ok i understand … but i dont want it to load init … i want it when i click on a link.
You should still put them in /site/plugins
. If you only need the functionality in specific situations (for example by calling the plugin from a template/snippet), simply wrap the code in the PHP file in a function. A very simple example:
site/plugins/your-plugin/your-plugin.php
:
function yourPlugin() {
require_once(__DIR__ . DS . 'code.php');
}
site/plugins/your-plugin/code.php
:
// your PHP code you want to load
You can now call yourPlugin()
from anywhere in your templates or snippets and the code will get loaded.
But in general, plugin code and external libraries should already define functions you can call and shouldn’t just run their code once you load the code. In that case, simply putting the actual code into the file your-plugin.php
works just fine and you will be able to call functions in the code file.
1 Like
Ok … the only thing why i still dont get is how i can do it when i created a new site.
If i do this there is no template or snippet for this site just the content with the .txt files.
Do you mean “when I created a new page”? Because I don’t really understand what you mean.
I mean creating a new Page in the Admin Panel.
When i did this i can only find the .txt files for the created page in the content folder and no template files.
And do you want to call the script via a link in your text file?
No … i just want to created a new page where i can put a script in it like a formailer.
Normally i do this with include(“blablabla.php”);
But i cant find a template for the created page … just only .txt files.
So thats why i dont get it to call functions in a template when no template is existing for the created page.
If you create a new page via the panel, your blueprints determine the possible templates for the new page. http://getkirby.com/docs/panel/blueprints
And the filename of the text file determines the template which is used for a text file. E.g. if you have a text file called test.txt, Kirby will check if there is a template file in /site/templates, which is called test.php and use this template to render the text file. If there is no such template, Kirby will fall back to the default.php template.
1 Like
Thank you so much … now i finally got it … 