Abbreviations / glossary

I don’t know and I think that’s really also an edge case. Normally, you would have to replace strings only in limited locations, i.e. long form text, which could be a textarea field or blocks field, not all over the place.

Of course, you can buffer all your stuff in your templates, then call the replacement on the buffered string. Or use JavaScript on the frontend or whatever.

it seems i’ll go the way of using kt() nearly everywhere… it’s a pity… but well… i’ll test if it will break things…

so i use the placeholder cookbook recipe with just a simple change:
instead of Str::template() il use strtr() which seems to do the same but without start/end-triggers. So no need of preg_replace_callback() or similar.

i did not understand the options-thingy completly… i would like to have the blueprint that the cookbook recipe recommend to place inside site.yml to be in a separate file that i use for ressources.
Could you give me hint on that? i don’t understand the syntax of options() in this case

In the example plugin we use site(), but you can of course replace this with `page(‘resources’), that doesn’t matter. If you don’t want to hardcode it, you could set up another config option for that

The cookbook recipe has example code, depending on what you do, you can throw out the stuff that you don’t need and modify everything to your liking.

1 Like

ok… project is down… fails are also helpfull… so i describe why the original idea was a bad one…

i oversaw, that automatic replacement will also replace parts of for example urls etc. on the site… also it does not reflect words in plural/singular or any grammar and on and on…

so for anyone with a similar idea:
a very intelligent matching algorythm would be needed for this… and that would be much more work than reworking text all over the website to use a kirbytag or placeholder-brackets…

well… much time lost… but i learned several things =)

@texnixe i am highly interested in the glossary kirbytag solution of the kirby-homepage… is this documented anywhere? or do i have to fish in the code?

Yes, get your fishing equipment out… But I think I pointed you to the relevant stuff, apart from the JS part of it, if you need this.

Maybe I will turn it into a recipe one day, but not today…

That’s probably just a matter of finding the right regex, but using delimiters like braces definitely makes the whole stuff easier.

Summary

i’m playing with the glossary tag of the kirby homepage, as mentioned here: Abbreviations / glossary - #2 by texnixe

i try to adapt the code for use with the drop-component of uikit.

so i try to reformat the output, but i always get the html tags of $tooltip rendered as text… not rendered as html… since i did not solve to add a non-associative attr to Html:span() (maybe you can help here, too) i try it plain like this:

    // GLOSSARY
    'glossary' => [
        'attr' => [
            'text'
        ],
        'html' => function ($tag) {

            if ($entry = Glossary::entry($tag->value)) {

                $content  = Glossary::content($entry);
                $headline = Html::a(Glossary::url($entry), $entry->title());
                $tooltip  = Html::div([$headline], ['class' => 'bold -mb:small']) . $content;

                return Html::a(Glossary::url($entry), $tag->text ?? $entry->title()) . '<span uk-drop class="uk-card uk-card-body uk-card-default">test ' . Html::span($tooltip) . '</span>';
            }

            return Glossary::missingTerm($tag->value);

        }
    ],

and if i use $tooltip without a Html::span(), kirby puts a closing </p>-tag and renders $tooltip afterwards

Edit… nevermind… found the problem: https://stackoverflow.com/a/10763952