mattmilburn/strapi-plugin-preview-button

When a value is unset, the URL retains the un-interpolated variable with curly brackets

zrothauser opened this issue ยท 3 comments

In this use case, I'm using a "page" content type, and the site's Home page is the only page to have an empty slug. When previewing other pages with slugs set, everything works as expected, but when trying to preview the homepage, the created URL path is /en/{slug} (or /en/%7Bslug%7D after the browser's URL encoding).

Maybe the default for an empty variable such as the slug should be to interpolate the query URL with an empty string?

Here is my config:

'preview-button': {
  enabled: true,
  config: {
    contentTypes: [
      {
        uid: 'api::page.page',
        draft: {
          url: env('STRAPI_PREVIEW_DRAFT_URL'),
          query: {
            type: 'page',
            slug: '{slug}',
            secret: env('STRAPI_PREVIEW_SECRET'),
            locale: '{locale}',
          },
        },
        published: {
          url: `${env('STRAPI_PREVIEW_PUBLISHED_URL')}/{locale}/{slug}`,
        },
      },
    ],
  },
}

Followup: this seems to happen when a default value is not configured for a field, and Strapi has the value set to null. Specifying an empty string as the default value for slug here is a workaround for the issue.

Hi @zrothauser I can certainly use an empty string instead of ignoring the empty values ๐Ÿ‘๐Ÿป I'll be sure to include this in an upcoming release.

@zrothauser The latest release for v1.0.1 now includes this update so unmatched values are replaced with an empty string ๐Ÿ‘๐Ÿป