Skip to content

Unable to inject tag name when using custom tagTitle #405

@jeff-horton-ho-sas

Description

@jeff-horton-ho-sas

The tags feature page documentation suggests that the default for the tag page is Posts tagged ‘{{ tag }}’, but if I use tags: {tagTitle: "Pages tagged ‘{{ tag }}’"} in the plugin config, the page title ends up being Pages tagged ‘{{ tag }}’.

Looking at the implementation, this is because the default is using a template string, but options.tagTitle from options can only be a static string with this implementation.

Possible solutions:

  1. Allow passing functions into tagTitle:
    title: typeof options?.tagTitle === 'function' 
        ? options?.tagTitle 
        : (data) => options?.tagTitle || `Posts tagged ‘${data.tag}’`
    and then the tagTitle could be specified as:
    tagTitle: (data) => `Pages tagged ‘${ data.tag }’`
  2. Use nunjucks to render the title:
    title: (data) => nunjucks.renderString(options?.tagTitle || "Posts tagged ‘{{ tag }}’", data)
    Which would then work as currently documented.

Happy to submit a PR for either option, please let me know which is preferred.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions