Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zrothauser opened this issue Oct 19, 2022 · 3 comments
Labels
request Request for a feature

Comments

@zrothauser
Copy link

zrothauser commented Oct 19, 2022

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}`,
        },
      },
    ],
  },
}
@zrothauser
Copy link
Author

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.

@mattmilburn
Copy link
Owner

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.

@mattmilburn mattmilburn added the request Request for a feature label Nov 10, 2022
@mattmilburn
Copy link
Owner

mattmilburn commented Nov 17, 2022

@zrothauser The latest release for v1.0.1 now includes this update so unmatched values are replaced with an empty string 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
request Request for a feature
Projects
None yet
Development

No branches or pull requests

2 participants