Thanks for your input! Feeling a bit dumb at the moment, because that simple isset solved the problem with $_GET:
if(isset($_GET['myvariable'])) echo htmlspecialchars($_GET['myvariable']);
else echo'nope';
For parsing the url, my brainbug was the same. This version works after adding array_key_exists:
$array_url_parse=parse_url($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
var_dump($array_url_parse);
if(array_key_exists('query', $array_url_parse))
{
echo '<br/>'.$array_url_parse['query'].'<br/>';
echo 'URL contains variables';
}
else echo 'URL does not contain variables';
So two checkmarks set, thanks to your hints - I should not be writing code at midnight anymore, I think.
I have to admit, that my knowledge about functions and classes is limited. I tried to get along with your suggested self::getQueryVar(), but still something is missing and I have no clue solving this error:
“Class ‘Grav\Plugin\Grav’ not found”
I did not find a solution within learn.getgrav.org or other forum threads.
use Grav\Common\Twig\Extension\GravExtension;
works, there is a folder and file within
root\system\src\Grav\Common\Twig\TwigExtension.php
But I do not find a folder
root\system\src\Grav\Plugin
within my local install via xampp, so
use Grav\Plugin\Grav;
seems to be useless. Theory: If the path starts with “Grav\Common”, it pushes one to root\system\src\Grav\Common and if a path starts with “*Grav\Plugins*”, it directs to root\user\plugins where there ist no folder and plugin named Grav that can be found?
My complete code is
<?php
namespace Grav\Plugin;
use Grav\Common\Twig\Extension\GravExtension;
use Grav\Plugin\Grav;
class ExampleTwigExtension extends GravExtension
{
public function getName()
{
return 'ExampleTwigExtension';
}
public function getFunctions(): array
{
return [
new \Twig_SimpleFunction('example', [$this, 'exampleFunction'])
];
}
public static function getQueryVar($var)
{
return Grav::instance()['uri']->query($var);
}
public function exampleFunction()
{
echo self::getQueryVar('myvariable');
}
}
About notices and warnings.
Yes, I considered primarily Contenido. I digged quite deep into that cms, but - because I am not a studied programmer and everything I know came time after time by dealing with JS, PHP, HTML and CSS in my spare time - I did not get that deep into the core as necessary to be more than a versatile user. So my knowledge is most of the time on point for what I want to do and if something does not work, I rtfm and also depend on community feedback. Again: Thanks to you!
So, learning more about functions and classes in general and especially using them within grav will be my next big chapter to deal with. There are different ways to walk for achieving goals in grav than in Contenido. learn.getgrav.org is quite good, but often it is - to me - more of a knowlege puzzle than a linear approach from a to z. Quite often the given information stays on top of the iceberg. Don’t get me wrong, I know how much work this is (I guess you saw this? [Handbuch für Einsteiger (contenido.org)](Handbuch für Einsteiger - Yes, although my questions might cause thoughts “Ah, some noob.”, that book works for so many people and considers quite an amount of indiviually developed modules. The approach is different and can be compared to a complete guided tour instead of a lexicon.) Well, I’ll dig through it till I become more familiar with all those dependencies and principles of grav. And, like I do with Contenido, I’ll of course help others with their issues if I can. I am not that kind of user which is just consuming.
Have a nice day!
Markus