krisa
April 9, 2019, 9:34am
1
I am not sure if this is related to this issue Snippet returning <pre> tags
But i really need super simple wp style “shortcode”. And this confuses me
<?php
Kirby::plugin('floriankarsten/peopletag', [
'tags' => [
'peoplebuilder' => [
'html' => function($tag) {
// this works properly
return '<a href="http://wikipedia.org">Wikipedia</a>';
// this returns escaped html with <pre> tags
return snippet('peoplebuilder', ['people'=> $tag->parent()->people()->toStructure() ], true);
}
]
]
]);
What i don’t understand is in K2 as i remember snippet function would just return html string.
I understand that i could use kirbytags:before
and kirbytags:after
hooks but shouldn’t the above work?
Thank you!
I can’t reproduce this, what is in your snippet?
What if you change the above to:
$html = snippet('peoplebuilder', ['people'=> $tag->parent()->people()->toStructure() ], true);
return $html;
krisa
April 9, 2019, 11:12am
3
Found the reason. Snippet was
<?php foreach($people as $p): ?>
<p><?= $p->name() ?></p>
<?php endforeach; ?>
It was because of indentation. I had tab there just for and that apparently tells markdown to wrap it as pre. So feature not a bug :))
<?php foreach($people as $p): ?>
<p><?= $p->name() ?></p>
<?php endforeach; ?>
This works so for anyone having those issues watch out for indentation if you are putting html into markdown before markdown was parsed.
krisa
April 9, 2019, 11:17am
4
Also for anyone coming here. It is only problem if you indent root elements from point of markdown. So if i just did this
<div>
<?php foreach($people as $p): ?>
<p><?= $p->name() ?></p>
<?php endforeach; ?>
</div>
It would have been just fine.
Or use two spaces instead of 4, I think.
Note that if you put empty lines in between like this, it will stop working again:
<div>
<?php foreach($people as $p): ?>
<p><?= $p->name() ?></p>
<?php endforeach; ?>
</div>
krisa
April 9, 2019, 11:24am
7
Well i use tabs for indentation everywhere except yaml where it is spec. Nevermind i think if somebody comeres to this post it will point them to right direction.
Thank you @texnixe !