# Render a string with kirbytext using page's files

**URL:** <https://forum.getkirby.com/t/render-a-string-with-kirbytext-using-pages-files/13775>\
**Category:** Questions\
**Tags:** v3\
**Created:** [April 12, 2019, 11:51am UTC](https://forum.getkirby.com/t/render-a-string-with-kirbytext-using-pages-files/13775 "2019-04-12T11:51:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![piaaaac](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/piaaaac/32/5568_2.png) [@piaaaac](https://forum.getkirby.com/u/piaaaac)\
**Post date:** [April 12, 2019, 11:51am UTC](https://forum.getkirby.com/t/render-a-string-with-kirbytext-using-pages-files/13775/1 "2019-04-12T11:51:20Z")

</div>

I want to render a page with its images, but before using kirbytext I need to transform all `#hashtags` in links `(link: http:// text: hashtag)`. I have a problem with images that don’t render, 'cause I’m not sure how to pass the page’s data to `kirbytext()`

```auto
function taggize($str){
  $re = '/#([a-zA-Z0-9-_]+)/m';
  return preg_replace($re, "(link: items/tag/$1 text: #$1)", $str);
}

kirbytext(taggize($item->text()->value()), $item); // error: array expected

kirbytext(taggize($item->text()->value()), $item->toArray()); // no images are rendered

```

Thanks for any help!

---

<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:** [April 12, 2019, 12:07pm UTC](https://forum.getkirby.com/t/render-a-string-with-kirbytext-using-pages-files/13775/2 "2019-04-12T12:07:47Z")

</div>

> [@piaaaac](#):
>
> kirbytext(taggize($item-\>text()-\>value()), $item-\>toArray());

```auto
kirbytext(taggize($item->text()->value()), [$item]);

```

---

<div class="post-metadata">

**Author:** ![piaaaac](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/piaaaac/32/5568_2.png) [@piaaaac](https://forum.getkirby.com/u/piaaaac)\
**Post date:** [April 12, 2019, 1:08pm UTC](https://forum.getkirby.com/t/render-a-string-with-kirbytext-using-pages-files/13775/3 "2019-04-12T13:08:06Z")

</div>

> [@texnixe](#):
>
> ```auto
> kirbytext(taggize($item->text()->value()), [$item]);
> 
> ```

Still not showing images ☹

Also, maybe you could update the [docs](https://getkirby.com/docs/reference/templates/helpers/kirbytext#example__parse-kirbytext-for-another-page) with the right solution.

---

<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:** [April 12, 2019, 1:14pm UTC](https://forum.getkirby.com/t/render-a-string-with-kirbytext-using-pages-files/13775/4 "2019-04-12T13:14:53Z")

</div>

Do you mean images that are added as KirbyTags? And what exactly are you replacing here, there seems to be an issue with parentheses here. Could you post some example text?

Updated docs.

---

<div class="post-metadata">

**Author:** ![piaaaac](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/piaaaac/32/5568_2.png) [@piaaaac](https://forum.getkirby.com/u/piaaaac)\
**Post date:** [April 12, 2019, 2:52pm UTC](https://forum.getkirby.com/t/render-a-string-with-kirbytext-using-pages-files/13775/5 "2019-04-12T14:52:13Z")

</div>

My page’s text in the panel looks like this:

```auto
(image: bitmap.jpg)
#ui #design

```

I want to turn all the hashtags that appear in the page’s text into links. For example in my output I want to automatically turn the string ‘#design’ into a link like this:

```auto
<a href="http://mysite.com/items/tag/design">#design</a>

```

And that works fine with the taggize function above.  
But to do so I can’t use the kirbytext function directly on the field, hence the need to use the kirbytext() helper and passing the page’s data to render the images.

Hope it’s clear now

---

<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:** [April 12, 2019, 3:05pm UTC](https://forum.getkirby.com/t/render-a-string-with-kirbytext-using-pages-files/13775/6 "2019-04-12T15:05:35Z")

</div>

> [@piaaaac](#):
>
> (image: bitmap.jpg) #ui #design

Works for me, but the issue is that you need to echo your stuff.

```auto
echo kirbytext(taggize($item->text()->value()), [$item]);

```

---

<div class="post-metadata">

**Author:** ![piaaaac](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/piaaaac/32/5568_2.png) [@piaaaac](https://forum.getkirby.com/u/piaaaac)\
**Post date:** [April 12, 2019, 4:55pm UTC](https://forum.getkirby.com/t/render-a-string-with-kirbytext-using-pages-files/13775/7 "2019-04-12T16:55:51Z")

</div>

That’s not the issue, I am echoing it in my template but tue images don’t show up.  
It seems the page’s data is not recognized.

```auto
// Page: items/cool-sites

$string = taggize($page->text()->value());
echo kirbytext($tring, [$page]);

// output html
<figure><img alt="" src="http://mysite.com/bitmap.jpg"></figure>
<a href="http://mysite.com/tag/ui">#ui</a>
<a href="http://mysite.com/tag/design">#design</a>

// expected output
<figure><img alt="" src="http://mysite.com/media/pages/items/cool-sites/3340574285-1555063277/bitmap.jpg"></figure>
…

```

If I use `$page->text()->kirbytext()` images render fine.

---

<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:** [April 12, 2019, 10:53pm UTC](https://forum.getkirby.com/t/render-a-string-with-kirbytext-using-pages-files/13775/8 "2019-04-12T22:53:17Z")

</div>

Have you tested this in a fresh Starterkit? Maybe something is interfering. Plugins?

What is your Kirby version?

Wouldn’t it make sense to use a custom KirbyTag for this purpose where you include the hashtags in the image tag:

```auto
(taggedimage: someimage tags: #ui, #design)

```

Then render that as figure tag with figcaption. Seem to be more semantically useful than links that are not tied to the image?

If these tags belong to the image, that is.

---

<div class="post-metadata">

**Author:** ![piaaaac](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/piaaaac/32/5568_2.png) [@piaaaac](https://forum.getkirby.com/u/piaaaac)\
**Post date:** [April 13, 2019, 11:39am UTC](https://forum.getkirby.com/t/render-a-string-with-kirbytext-using-pages-files/13775/9 "2019-04-13T11:39:15Z")

</div>

> [@texnixe](#):
>
> If these tags belong to the image, that is.

Actually they don’t. Images and tags are independent from one another.

Ok, I’ll try again on a fresh starterkit.
