1

According to EE3 documentation:

/name/{first_name}/{last_name} 

with Require All Segments set to no should match

/name/Enrico/Fermi

/name/Enrico

/name/III

/name

I am trying to use a template route to find a segment_1 parameter (such as a n language site /es/), so that my normal template is loaded at url:

/group/template_variable

and my language version is:

/es/group/template_variable

I created the route as follows:

/es/group/{template_variable}

and i have "reuaire all segments" set to NO.

currently, /es/group/example will match that route, and find the template correctly, but /es/group/ loads nothing (which it should still match per the EE documentation)

Am I doing something wrong here?

| improve this question | | | | |
0

The documentation for Template Routes is pretty lamentable, so not a surprise you are having difficulties.

Each template can have only one route to it, and equally each route definition can only link to a single specific template.

It is not clear from your question whether you plan to link all routes of form /es/group/something to the same template. If you do, you need to generalise the route definition to accept 'anything' in the third segment. Something like:

/es/group/{alpha_dash}

{alpha_dash} is one of the constructs you can use in a route to tell EE what to accept in a segment (in this case alphabetic characters, 0 through 9, underscore, and dash).

With this rule anything routing to /group/template_variable would be unaffected, but the /es/ prefixed routes would only go to the template you put the route next to in the CP.

If you want a route to go to a specific (different) template depending on what is in segment 3 you'd need a different route instruction for each template - one for each template. So something like

route /es/group/dogs -> to the spanish dogs template

route /es/group/cats -> to the spanish cats template

As before, the /group/cats template etc. should continue to work fine with this route in place.

If you have multiple languages you can generalise these rules by replacing the /es/ with a more general rule for that segment. If all of the language flags are two letter, and you have no two-letter template groups something like this might work:

/{max_length[2]}/dogs -> routes all URLs of form /xx/dogs to /dogs

HTH

| improve this answer | | | | |
  • Still giving me an issue. problem is, I need /es/group/ to go to the page, as well as /es/group/dogs to go to the page such that (assuming the page were about pets) I can specify a default value if no pet is given, or if /dogs is in the url, I can load data specific to dogs. – Drew Major Feb 16 '17 at 19:14
  • Oh - OK. Well there are two ways you could try to get a solution. One is to put in once of these fiendish multi-rule routes - something like: – JCOGS Design Feb 17 '17 at 9:17
  • {tag:max_length[2]|group}/{tag2:group} - with 'segments required' set to no. This (should) route anything with the form /group/ or /xx/group. If you have several 'groups' just add these as further pipe elements to each segment - e.g {tag:max_length[2]|cats|dogs}/{tag2:cats|dogs} - but to be honest these complex rules never seem that good - so there is another solution you could try... (next comment) – JCOGS Design Feb 17 '17 at 9:25
  • If you don't have that many use cases, the alternative is to skip Template Routes completely, and do the same thing using either layout or embed. What you do is create all the templates that you might need (so create a template group called 'es' and put a template called 'group' within etc.). Then fill these templates with a layout or embed instruction that populates them with the template you want to use. I use stash:embed for this - with templates having the following one-line entry: {stash:embed:target_template_name process="start"} - as a solution it is a bit crude, but works. – JCOGS Design Feb 17 '17 at 9:30

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.