9

We have a some conditional logic for a dashboard style setup. We have urls like :

neptune/{id}/details
neptune/{id}/options
neptune/{id}/confirm

etc..

The actual urls accessible depend on the status of the elements in question, and the whole process has a flow setup - the user has to go through each part in turn, ie. details > options > confirm, however they can go back and revise and drop out entirely and pick up where they left off later.

This all works fine, but to smooth out things we'd ideally have a way to automatically force a redirect from a urls based on the current state. If this were ExpressionEngine we'd have a tag like :

{redirect="neptune/{id}/confirm"}

What's the equivalent Craft/Twig setup? Or is there an alternative better setup.

Note : this isn't for the main flow of the user, only needed for the actual edge cases where a user may revisit (ie. manually) an out of flow url somehow, so isn't related to the core logic.

10

Take a look at Craft's redirect function:

{% redirect '/' %}

In your case it would look like this:

{% redirect 'neptune/' ~ id ~ '/confirm' %}
2

For this, my Retour plugin would work well, because it has a FieldType that you can attach to existing Entries, and do the redirect based on data from the entries.

So you can set up a rule in the FieldType like .*RecipeID={recipeid} as the default Legacy URL Pattern for the FieldType, and it'll pull the value from the {recipeid} field in each entry, and create a redirect for it to the new entry.

It also doesn't do anything unless a 404 exception actually occurs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.