strapi-webtools icon indicating copy to clipboard operation
strapi-webtools copied to clipboard

[Feature] Allow simple pseudo logic in patterns.

Open douwepausma opened this issue 3 months ago • 3 comments

Addon

No specific addon – This feature request is related to Webtools Core

Summary

Allow simple pseudo logic, like a shorthand if-else statement, to use fixed strings or other fields based on the value of the checked field. See suggested solution for an example.

Why is it needed?

In our case we have a vacancy content-type which has a toggle called volunteer that decides whether it's a payed position or not. We use the sames content-type as all the fields are in common. Some simple logic like the example below could be very use full in displaying the content under a different parent page. I can imagine other areas where this functionality could be useful as well.

Suggested solution(s)

# volunteer = true
# slug = barkeeper
/[volunteer ? 'volunteer' : 'careers']/[slug]
-> "/volunteer/barkeeper"

# volunteer = false
# slug = accountant
/[volunteer ? 'volunteer' : 'careers']/[slug]
-> "/careers/accountant"

Related issue(s)/PR(s)

Maybe this can be implemented in conjunction with #283

douwepausma avatar Nov 05 '25 14:11 douwepausma

Hi @douwepausma,

I think you raise a valid point. I'm just not sure if I'm on board with including psuedo logic in the patterns. It might make the URL patterns feel a bit like magic with hidden features. What do you think about the following solution:

We introduce a sort of hook/middleware for the URL alias generation. It allows you to overwrite the URL generation logic, essentially overwriting any existing patterns, and gives you full control over how you want the URL alias to be generated. I think this allows more flexibility, also for cases where the logic might be even more complex.

boazpoolman avatar Nov 06 '25 09:11 boazpoolman

@boazpoolman I totally agree, it would indeed be a bit obscure. A hook is a better idea, maybe in a similar manner as is done with the slugify function in the plugin's config?

douwepausma avatar Nov 06 '25 10:11 douwepausma

@douwepausma yeah, that's what I had in mind too.

boazpoolman avatar Nov 06 '25 12:11 boazpoolman