AMP ⚡ - Taking on without making plugins

I am just messing around with default Grav set-up and thinking how can I add AMP (Accelerated Mobile Pages) to existing news site.

So I started off with a partial base-amp.html.twig that will be a boiler plate for all AMP pages.
The challenging part is I don’t know how can I “call” it to generate for me my AMP version of article if I want have my post just once and let Grav create AMP version.

I would start by creating a default.amp.twig file, and by adding amp to the system.pages.types setting (in the System config).

This way you can simply add .amp to a page URL to render the AMP version.

Then you need to edit the base.html.twig file to include the link to your AMP page

<link rel="amphtml" href="{{ page.url(true, true) }}.amp" />

@flaviocopes I just tested my system.pages.types and tried adding .rss and it gave me an error. When I add .amp, it loads default .html page? Do I am missing something?

Still could not solve it. Anyone got a hint?

You need to define amp in Media types so Grav knows the MIME type. Then you need to add amp to the system.pages.types, then provide appropriate .amp.twig templates to render.

@rhukster something still isn’t right. In my system/config/system.yamlfile I have addedamp` to the end:

     types: [txt,xml,html,htm,json,rss,atom,amp]   # list of valid page types

Now this still doesn’t work. I checked other page types and when I add for example .rss to the end of the link I am getting E_WARNING - array_merge(): Argument #1 is not an array in the browser. When I try to access link with .amp at the end, I can see my page source code, not the amp version of the page.


What was the problem?

That sounds like it covers creating a template for amp page, but you also need to ensure the content is using the correct markup. I would like to see how could be integrated with Twig and Grav

How did you make it work ?