Skip to content

docs(readme): document the seo.*() methods and their use from PHP - #65

Merged
Fredxd merged 2 commits into
AppoloDev:mainfrom
Vondry:docs/seo-twig-methods
Oct 23, 2026
Merged

Fredxd merged 2 commits into
AppoloDev:mainfrom
Vondry:docs/seo-twig-methods

Conversation

@Vondry

@Vondry Vondry commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #42

Summary

#42 asks how to use the extension from a custom Twig function, and whether to use Appolo\BoltSeo\Seo\Seo;. The README only showed seo.title() and seo.metatags(), so it didn't answer that.

This PR is documentation only. There are no code changes.

Changes

  1. docs(readme): document the seo.*() methods and their use from PHP
    • A table of all public methods of the seo Twig global (title(), description(), keywords(), image(), robots(), ogtype(), canonical()), with a short Twig example.
    • The order in which each value is resolved: override_default → the record's SEO field → the record's own fields → the default config.
    • For How to use it in my twig Function? #42: in PHP you don't create the Seo class yourself. The same object is the seo Twig global, reachable through Environment::getGlobals() from a Twig function with needs_environment.
    • The variables a custom meta tags template receives.
  2. docs(readme): use the real meta tags template filename: the README said _metatags.twig in three places, but the shipped template (and the file to copy when overriding it) is _metatags.html.twig.

Note for #42

public function myDescription(Environment $twig): string
{
    /** @var Seo $seo */
    $seo = $twig->getGlobals()['seo'];

    return $seo->description();
}

registered with new TwigFunction('my_description', $this->myDescription(...), ['needs_environment' => true]).

Manual verification (Bolt 6.1.9)

On a fresh bolt/project install, I checked every snippet in the README:

  • Each seo.*() method listed renders in a theme template.
  • The PHP example, dropped verbatim into a Twig extension in src/Twig/, returns the same value as seo.description().
  • The override steps, using the corrected _metatags.html.twig filename, make the extension render the copy in the theme folder.

Tests

No behaviour changes, so no new tests.

The README referred to `_metatags.twig`, but the template the extension
ships, and the one to copy when overriding it, is `_metatags.html.twig`.
The README only showed `seo.title()` and `seo.metatags()`. Document the
other public methods of the `seo` Twig global, the order in which each
value is resolved, and how to reach the same object from PHP (e.g. in a
custom Twig function) through `Environment::getGlobals()`, instead of
creating the Seo class yourself. Also list the variables a custom meta
tags template receives.
@Fredxd
Fredxd merged commit 1fa63bd into AppoloDev:main Oct 23, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to use it in my twig Function?

2 participants