The power of placeholders

@texnixe:

Thank you very much for this Cookbook article https://getkirby.com/docs/cookbook/extensions/use-placeholders. I like it very much.

But I have two questions:

1.) Can you please explain, why the hook changes from the code in #06 to #07?

2.) I tested the final code in K3, but I cannot see any difference in the rendered html code of a page, if I change the position in the toggle field. The html code has no change. What does this field do if the content field with the original placeholder is rendered by kirbytext()?

Thank you for your answer.

  1. The change is to also make it possible to define options in the config.php file (globally) instead of in the blueprint alone. The global defined options will be merged with the ones defined in the current field’s blueprint.

  2. I haven’t tested this tbh, but as I read the code the placeholders (both defined globally and in the current field blueprint) should get replaced upon each {field}->kirbytext() call (when they are toggled “on”).

If you use an inline placeholder

This is some text with a {{ inline.placeholder }} bla bla

it shouldn’t contain block level elements.

But you can also have block level replacements

Replacement for `{{ something }}"

# A headline

Some text bla bla

(image: someimage.jpg)

In text:

Some text bla bla

{{ something }}

Some more text

In that case, the replacement should be parsed with Kirbytext, which will happen if you set the block toggle to true. Of course, this placeholder shouldn’t be used inside a paragraph.

Thank you @texnixe for the answer to the second question. I will test soon.

But what about the different hooks kirbytext:before in #06 and kirbytags:before in #07?

@texnixe:

Sorry to ask again, but I want to understand why the code is different in the two parts of the code:

https://getkirby.com/docs/cookbook/extensions/use-placeholders#wrapping-the-replacement-code-in-a-hook:

https://getkirby.com/docs/cookbook/extensions/use-placeholders#the-final-plugin

I would like to understand this so that I can incorporate the underlying consideration in my code in the future.

In this case, it doesn’t matter which of the two hooks you use, see https://getkirby.com/docs/cookbook/extensions/kirbytext-hooks

1 Like

Thank you very much for your answer.

My testing of the two hooks had shown me no difference. Therefore I had not understood the two code variants without a corresponding explanation of what the code change does.