Accessing site() in custom tags? - freezing localhost and browser

I have been sitting at a custom tag to somewhat simplify and customize some internal linking towards related pages to reference in blog articles for example…

while trying to access the site() object within the tag, i found myself that my local server became very unresponsive thus not loading pages anymore until i changed the code…

I have taken the approach linked there using

$var = kirby()->site();

as well as somewhat accessing

<?php

kirbytext::$tags['relate'] = array(
  'html' => function($tag) {
		$output = null;
		$s = kirby()->site();
		// UID = $Tag
		if($s->find($tag)){
			$p = $s->find($tag);
// ... some more other stuff...

but my browser window, as well as the actual loading seems weird. Firefox Developer Edition is somewhat “flashing up” at the top bar and becoming unresponsive. Chrome says site is not reachable instead of giving any kind of whoops error.

Could you please post the whole thing?

I am stupid…

<?php

kirbytext::$tags['relate'] = array(
  'html' => function($tag) {
		$output = null;
		$s = kirby()->site();
		// UID = $Tag
		if($s->find($tag->attr('relate'))){
			$p = $s->find($tag->attr('relate'));
			if($p->cover()){
					$output .= '<div class="grid-x">
					'.$tag->attr('relate').'
					</div>';
			}
		}
    return $output;
  });

 ?>

this works…

Was just gonna say, there’s something wrong with your code… I’d nevertheless improve it a bit:

<?php

kirbytext::$tags['relate'] = array(
  'html' => function($tag) {
		$output = null;
		$s = kirby()->site();
		// UID = $Tag
		if($p = $s->find($tag->attr('relate'))){

			if($title = $p->title()){
					$output .= '<div class="grid-x">
					'.$title.'
					</div>';
			}
		}
    return '<a href="">Test</a>';
  });

yeah. the refinement won’t stop there. i just happened to run into the problem so i focused on fixing it leaving everything super dirty with some dummy code. makes it easier to understand and debug (for me)

still won’t make too much sense :wink: