Cant select variable


iam new to Kirby and php. But i want to write a plugin.
I want to be able to put a .pdf file in a object tag. Because if i drag and drop it in the panel view.
its create a file link (file:mypdf.pdf) So that users can click on the a href on my site. But i want the .pdf in a object tag. Because then its always visible.
But i got a Undefined variable. here is the script.

    kirbytext::$tags['pdf'] = array(
        'html' => function($tag) {
            $url	 = $tag->attr('pdf');
            $dir = $page->dirname();
            return '<object type="application/pdf" data="' . $dir . $url . '">
                        <p>PDF error :(</p>

for some reason the code formating is al wrong, and it leaves a the part after return.
So here is a screen shot of the code

I just fixed the formatting/highlighting in your post.

1 Like

And I think it should be $tag->page() instead of $page.

1 Like

The following should work and is also the correct way to get the URL:

    kirbytext::$tags['pdf'] = array(
        'html' => function($tag) {
            $pdf = $tag->attr('pdf');
            $url = $tag->file($pdf)->url();
            return '<object type="application/pdf" data="' . $url . '">
                        <p>PDF error :(</p>
1 Like

wow you guys rock!
It works perfectly tanks!
I have just one more question.
If i drag a .pdf into the textfield it becomes (file:mypdf.pdf)
is it also posible to automaticly make it (pdf:mypdf.pdf)?

Not without changing the core code of Kirby.

But then i would replace the default value. is it also possible to only change it when a .pdf is dragged in?

You could replace the highlighted line with

if($this->extension() == 'pdf') {
  return '(pdf: ' . $this->filename() . ')';
} else {
  return '(file: ' . $this->filename() . ')';

But I just wanna emphasize that I wouldn’t recommend changing the core code as it will be removed again with every update.

I see, tanks
Is there any other way to fix this problem.
And how often does kirby get updated?
And is kirby auto updated?

Currently there isn’t any other way to do this.
Kirby is updated every few weeks but is not auto-updated.

So do i need to redownload it from the site every time? And use FTP to put it on my server?

You can also use Git to update Kirby and push to a repo on your server.