fanningert / kirbycms-extension-gmaps

This is a Kirbytag to integrate Google Maps API in your website
GNU General Public License v3.0
10 stars 2 forks source link

Allow kirbytag syntax #9

Closed rzschoch closed 9 years ago

rzschoch commented 9 years ago

Thank you for your nice extension, it really helps a lot.

Is it possible to use the kirbytags syntax in templates, like so (http://getkirby.com/docs/cheatsheet/helpers/kirbytag):

kirbytag(array('googlemaps' => 'Vienna'));

I always got an error, so I can’t use your extension at the moment. That is, because your given examples don’t work for me, unfortunately. The line ...

use at\fanninger\kirby\extension\gmaps\GMaps;

... throws an exception.

Thanks for your help!

fanningert commented 9 years ago

The code for kirbytag is not working with my plugin (I think so, but I will test it), because I load my plugins in the pre time and not in the tag time. How did your plugin directory looks like. It should be...

{kirbyinstall_dir}
  - site
    - plugins
      - kirbycms-extension-gmaps
        - kirbycms-extension-gmaps-lib.php
        - kirbycms-extension-gmaps.php
        - ...

What error/exception did you get? Please also write the used code for the execution of my plugin.

fanningert commented 9 years ago

You are correct. I get following erros.

Notice: Undefined index: content in /srv/http/thomas/site/plugins/kirbycms-extension-gmaps/kirbycms-extension-gmaps-lib.php on line 221
Notice: Undefined index: content in /srv/http/thomas/site/plugins/kirbycms-extension-gmaps/kirbycms-extension-gmaps-lib.php on line 235
Notice: Undefined index: content in /srv/http/thomas/site/plugins/kirbycms-extension-gmaps/kirbycms-extension-gmaps-lib.php on line 246
Notice: Undefined index: content in /srv/http/thomas/site/plugins/kirbycms-extension-gmaps/kirbycms-extension-gmaps-lib.php on line 257

I will correct this.

fanningert commented 9 years ago

Errors are away, but the parameter are not supplied to function to create the html code

fanningert commented 9 years ago

Bug is now corrected. But I also found a error in my documentation. I updated the README.md file.

Here now the working example.

use at\fanninger\kirby\extension\gmaps\GMaps;

$attr = array();
$attr[GMaps::JS_ATTR_LAT] = 35.7152128;
$attr[GMaps::JS_ATTR_LNG] = 139.7981552;
$attr[GMaps::JS_ATTR_ZOOM] = 4;
echo GMaps::getGMap($page, $attr);
rzschoch commented 9 years ago

Thanks for your time and the fixed issues I didn’t have (but it will certainly help somebody) :)

I’m not sure if I understood your documentation, but when I try to use your php examples in my snippets or templates (or my own kirbytags) I’m not able to import your GMaps extension with the use syntax (example: use at\fanninger\kirby\extension\gmaps\GMaps;).

When I implement it like that, this error is thrown: Parse error: syntax error, unexpected 'use' (T_USE)

Do you have any advice for me? My purpose is to have blueprint fields (in the panel) for filling a place or coordinates.

fanningert commented 9 years ago

Ok, currently the tag don't support fields as parameter, but this is a open point on my todo list. It should be easy to implement. I already support this in my image plugin. Syntax: {page-field} or {file-field} for KLM files. Example: (googlemaps lat: {page-lat} lng: {page-lng} zoom: {page-zoom}) When I have time this weekend, I will implement this feature in the package.

Now to your error message. I test it with my template files and it works. Did the tag work? Example: (googlemaps lat: 35.7152128 lng: 139.7981552 zoom: 4) Did you use the use in a function? -> see link

The use keyword must be declared in the outermost scope of a file (the global scope) or inside namespace declarations. This is because the importing is done at compile time and not runtime, so it cannot be block scoped.

When you would like to use it in a function, write the code in this form.

$attr = array();
$attr[at\fanninger\kirby\extension\gmaps\GMaps::JS_ATTR_LAT] = 35.7152128;
$attr[at\fanninger\kirby\extension\gmaps\GMaps::JS_ATTR_LNG] = 139.7981552;
$attr[at\fanninger\kirby\extension\gmaps\GMaps::JS_ATTR_ZOOM] = 4;
echo at\fanninger\kirby\extension\gmaps\GMaps::getGMap($page, $attr);
fanningert commented 9 years ago

I add page field support for some parameters to the plugin.

Example: (googlemaps lat: {page-lat} lng: {page-lng} zoom: {page-zoom})

rzschoch commented 9 years ago

It now works, thanks. The problem was the scope indeed ...

However, I’m also looking forward to your fields as parameter feature.

fanningert commented 9 years ago

@rzschoch For the first parameters the field support is active in the current version.