Calling shortcodes from config file

I’m trying to create a default meta in WP Yoast SEO style. The idea is to have a parameter in config.toml that is called when I don’t have any title or description data in my markdown file.

I have this code in my header partial

{{ if eq .Type "post" }}
{{$title_default = .Site.Params.post_title | markdownify }}
{{ else if eq .Type "category" }}
{{$title_default = .Site.Params.category_title | markdownify }}
{{ else if eq .Type "tag" }}
{{$title_default = .Site.Params.tag_title | markdownify }}
{{ end }}

And than I call a condition

<title>{{if .Title}}{{.Title | markdownify}}{{else}}{{$title_default}}{{end}}</title>

In my config file I have this params

page_title = "{{<post_title>}} {{<sep>}} 🏆 {{<sitename>}} some text"
category_title = "Some text {{<post_title>}} {{<sep>}} {{<sitename>}}"
provider_title = "{{<post_title>}} some text {{<post_title>}}"

It works pretty well, all except the {{<post_title>}} part. I’m trying to get post name, but it always gets content from my main page md file. How can I fix it, or is there any other way to make dynamic meta in config?

Your approach seems complex.

You might find it easier to use tokens in your configuration strings.

site configuration

[params.title]
categories = 'category @SITE_TITLE@ @FOO@'
tags = 'tag @SITE_TITLE@ @FOO@'
posts = 'post @SITE_TITLE@ @FOO@'
page = 'default @SITE_TITLE@ @FOO@' # For pages in root (home, about, etc)

template

{{/* Get page path for error messages. */}}
{{ $path := "" }}
{{ with .File }}
    {{ $path = .Path }}
{{ else }}
  {{ $path = .Path }}
{{ end }}

{{/* Get title. */}}
{{ $title := "" }}
{{ with .Title }}
  {{ $title = . }}
{{ else }}
  {{ with index site.Params.title .Type }}
    {{ $title = . | replaceRE `@SITE_TITLE@` site.Title | replaceRE `@FOO@` "something" }}
  {{ else }}
    {{ errorf "Unable to determine title for %s of type %q" $path .Type }}
  {{ end }}
{{ end }}

{{/* Render title. */}}
<title>{{ $title }}</title>

Thanx, it works great for me!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.