Conditional AMP rendering


#1

I note seen this asked in Kirby 3 context

I am using representation to direct to AMP content by adding .amp to the end of the page URL

But how do I change how KirbyText renders based on this.

For example <img> becomes <amp-img>

I would rather not have to have 2 contents, but a single content rendered slightly different.

Is this possible?


#2

You could replace image tags/other tags that need to be modified with a kirbytext:after hook.

I’m not familiar with AMP requirements, but you could also create alternative tags, and then use kirbytext:pre hooks to replace (img: with (amp-img), etc.


#3

You mean replace every single tag? Would that not also break the drag drop of images into articles?

I have hundreds of pages, so was hoping for a one hit solution.


#4

That filter would then be applied everywhere (well, conditionally if AMP page).


#5

What I meant was, I would need to replace every single image kirbytag? Or could I extend the image kirbytag?

Sorry I have not used this hook, and not quite following it.


#6

As I said, the filter would then automatically replace every tag.

An alternative would be this here: Deactivate specific tag (or plugin) on AMP version

You could also extend the tag.


#7

I will have a look, still massively confused, the hook docs don’t really tell me anything.


#8

Is there docs on extending a single kirbytag? And not sure how to detect a reflection at the moment?


#9

Example of a hook in action: https://getkirby.com/docs/cookbook/extension/columns-in-kirbytext