Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

AMP ⚡ - Taking on without making plugins

Started by Muut Archive 10 years ago · 9 replies · 646 views
10 years ago

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.

10 years ago

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

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

@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?

10 years ago

Still could not solve it. Anyone got a hint?

10 years ago

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.

10 years ago

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

YAML
pages:
     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.

10 years ago

Allright! I MADE IT WORKING WITHOUT PLUGINS. YAY!

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1323 9 years ago
Archive · by Muut Archive, 9 years ago
2 920 9 years ago
Archive · by Muut Archive, 9 years ago
2 4048 9 years ago
Archive · by Muut Archive, 9 years ago
1 2924 9 years ago
Archive · by Muut Archive, 9 years ago
3 1106 9 years ago