# Link inside Custom Kirbytag

**URL:** <https://forum.getkirby.com/t/link-inside-custom-kirbytag/9425>\
**Category:** Questions\
**Tags:** v2\
**Created:** [January 11, 2018, 1:18pm UTC](https://forum.getkirby.com/t/link-inside-custom-kirbytag/9425 "2018-01-11T13:18:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ebbel](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@Ebbel](https://forum.getkirby.com/u/Ebbel)\
**Post date:** [January 11, 2018, 1:18pm UTC](https://forum.getkirby.com/t/link-inside-custom-kirbytag/9425/1 "2018-01-11T13:18:40Z")

</div>

I have this Problem, that I have created a new Kirbytag which was created so the users can easily create Call-To-Actions without the knowledge of HTML/CSS. But I am running against a wall when trying to use a link inside the Kirbytag (Kirbytag inside Kirbytag).

**This is the Tag which is used for Standard Text insert:**  
`(cta: Call-To-Action Text)`

**And this is the one with the Link inside the KirbyTag**  
`(cta: Call-To-Action Text with (link: /contact text: Link))`

**Kirbytag:**

> kirbytext::$tags[‘cta’] = array(  
> ‘attr’ =\> array(  
> ),  
> ‘html’ =\> function($tag) {

```
$article = $tag->attr('cta');
return '<div class="' . 'cta-content' . '">' . $article . '</div>';

```

> }  
> );

Does anyone know how i would manage to do this?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 11, 2018, 1:22pm UTC](https://forum.getkirby.com/t/link-inside-custom-kirbytag/9425/2 "2018-01-11T13:22:17Z")

</div>

You can’t nest Kirbytags, I suggest you add the link as an option within your own tag.

```nohighlight
(cta: Call-to-action-text link: /contact text: Link)

```

---

<div class="post-metadata">

**Author:** ![Ebbel](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@Ebbel](https://forum.getkirby.com/u/Ebbel)\
**Post date:** [January 11, 2018, 1:27pm UTC](https://forum.getkirby.com/t/link-inside-custom-kirbytag/9425/3 "2018-01-11T13:27:02Z")

</div>

Thanks for your Help!

---

<div class="post-metadata">

**Author:** ![Ebbel](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@Ebbel](https://forum.getkirby.com/u/Ebbel)\
**Post date:** [January 11, 2018, 1:37pm UTC](https://forum.getkirby.com/t/link-inside-custom-kirbytag/9425/4 "2018-01-11T13:37:27Z")

</div>

But that also would deny me using Google Event Tracking or is there a way around this (I dont want to hardcode it since the Tracking has to be dynamic)?

**If I did this:**  
`(cta: Call-to-action-text link: onclick="gtag('event', 'click', {'event_category': 'email','event_label': 'jobs'});" text: Link)`

I would run into problems.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 11, 2018, 1:39pm UTC](https://forum.getkirby.com/t/link-inside-custom-kirbytag/9425/5 "2018-01-11T13:39:34Z")

</div>

I’m afraid I don’t quite understand. What is the difference between adding the link with the link tag or adding it directly in your custom tag? Of course, you would have to modify your tag to include the link?

---

<div class="post-metadata">

**Author:** ![Ebbel](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@Ebbel](https://forum.getkirby.com/u/Ebbel)\
**Post date:** [January 11, 2018, 1:47pm UTC](https://forum.getkirby.com/t/link-inside-custom-kirbytag/9425/6 "2018-01-11T13:47:20Z")

</div>

Sorry I copyed my Kirbytag wrong:

```
  (cta: CallToAction InfoText link: /contact tracking: onclick="gtag('event', 'click', {'event_category': 'email','event_label': 'jobs'});")

```

If i did this the output on the Website would break just like with the nested Kirbytags.

The reason I dont want to direcly add the Tracking inside the Kirbytag (in the tags.php) is because on One Page of the Website I might want to create a Call-To-Action linking to the contact Page with a Individual Tracking Code.  
**Example:**  
`(cta: CallToAction InfoText link: /contact tracking: onclick="gtag('event', 'click', {'event_category': 'email','event_label': 'jobs'});")`

But at the same time I want to have a Call-To-Action on a different page and with a different Tracking Code.  
**Example:**  
`(cta: CallToAction InfoText link: /profile tracking: onclick="gtag('event', 'click', {'event_category': 'email','event_label': 'profile'});")`

If the Tracking Code was hardcoded this would not be possible.

My current tags.php:

```
kirbytext::$tags['cta'] = array(
'attr' => array(
  'link',
  'tracking
  ),
  'html' => function($tag) {

  $article = $tag->attr('cta');
  $link = $tag->attr('link', 'cta');
  $tracking = $tag->attr('tracking', 'cta');
  return '<a ' . $tracking . ' href="'. $link . '"><div class="' . 'cta-content' . '">' . $article . '</div></a>';

  }
);
```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 11, 2018, 1:57pm UTC](https://forum.getkirby.com/t/link-inside-custom-kirbytag/9425/7 "2018-01-11T13:57:53Z")

</div>

I see, this is due to the fact that you can’t use parenthesis inside Kirbytags without escaping them, see [this post](https://forum.getkirby.com/t/way-to-use-parenthesis-inside-kirbytag/861?u=lukasbestle) for a possible workaround.

However, since the code is always the same only with a different label, you might as well include those as attributes:

```auto
(cta: CallToAction InfoText link: /contact event-label: jobs )

```

etc. if you need categories as well.

---

<div class="post-metadata">

**Author:** ![Ebbel](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@Ebbel](https://forum.getkirby.com/u/Ebbel)\
**Post date:** [January 11, 2018, 1:58pm UTC](https://forum.getkirby.com/t/link-inside-custom-kirbytag/9425/8 "2018-01-11T13:58:34Z")

</div>

You are completly right… 😃 Thanks alot like always!

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:30pm UTC](https://forum.getkirby.com/t/link-inside-custom-kirbytag/9425/9 "2025-02-06T17:30:15Z")

</div>

Archived on February 6, 2025, 5:30pm UTC


