Help for simple hint kirbytag

Hi,
Based on the examples in the docs (see here), I tried to make a simple “tooltip” kirbytag (hint.php) to be invoked by (hint: text: bla bla bla tip: lorem sup bla) with the following code:

<?php
kirbytext::$tags['hint'] = array(
  'attr' => array(
    'text',
    'tip'
  ),
  'html' => function($tag) {
    $url   = '#';
    $text  = $tag->attr('text');
    $tip   = $tag->attr('tip');

    return '<a herf="" data-tooltip="' . $tag->attr('tip') . '">' . $text . '</a>';
  }
);

It seems to works so far but I would like to have this tag applying also for a non-link (meaning without <a>xxx</a> just for a simple text. I turn around the code but my very poor skills in php are not helpful.
Thanks for your help.

I’d use an option link: true/false and then depending on that value, either return a link or simple text.

BTW. Why do you use the text attribute, wouldn’t it be easier for the user to type the text directly after hint, instead of leaving that blank?

(hint: Some hint text tip: some tip text link: false)

You would get the the content after hint with $tag->attribute('hint') then.

Thanks for the swift answer.
I use the following code

<?php

kirbytext::$tags['hint'] = array(
  'attr' => array(
    'tip',
    'link'
  ),

  'html' => function($tag) {
    $tip   = $tag->attr('tip');

    return '<a herf="" data-tooltip="' . $tag->attr('tip') . '"> ' . $tag->attr('hint') . '</a>';

  }
);

But I don’t know how to use the option link: true/false as suggested. Is there some additional code to add in the above example ?

You would have to use an if statement, something like this:

<?php

kirbytext::$tags['hint'] = array(
  'attr' => array(
    'tip',
    'link'
  ),
  
  // set the default to true
  $link = $tag->attr('link');
  if($link == '') {
   $link = true;
  }

  'html' => function($tag) {
    $tip   = $tag->attr('tip');
   if($link) {
    return '<a herf="" data-tooltip="' . $tag->attr('tip') . '"> ' . $tag->attr('hint') . '</a>';
  } else
   return $tag->attr('hint');

  }
);

the above code doesn’t work.
I got the following error:
syntax error, unexpected ';', expecting ')'
on the line $link = $tag->attr('link');
try to correct but unsuccessfully.

I was on the wrong line, sorry:

<?php

kirbytext::$tags['hint'] = array(
  'attr' => array(
    'tip',
    'link'
  ),
  
  'html' => function($tag) {
    
   // set the default to true
   $link = $tag->attr('link');
   if($link == '') {
     $link = true;
   }
   $tip   = $tag->attr('tip');
   if($link) {
    return '<a herf="" data-tooltip="' . $tag->attr('tip') . '"> ' . $tag->attr('hint') . '</a>';
  } else
  
    return $tag->attr('hint');
  }
);

Fine,
it works
Thank you