1

I was wondering if it was possible to use an alias inside a field in the Admin panel. For example, I have a global section called "Navigation" which contains a matrix called "Links". This matrix allows the client to create links for their navigation bar. Inside each matrix block, is a field called "Link Url" where the client can put in a link.

Right now the client is hardcoding urls for the production site, so my links don't work on my dev environment. I would like to rectify this, with some type of elegant solution.

Any ideas?

Glorfindel
  • 203
  • 1
  • 3
  • 10
Dan Zuzevich
  • 487
  • 2
  • 18

1 Answers1

1

A good approach would be to use the UrlHelper class it has a function UrlHelper::url() that is available in Twig and will return the correct URL for a certain path. So you could ask your client to not insert the entire URL, only the path -> instead of example.com/entries -> entries or you can include a custom Twig function/behavior that strips the domain before you use the {{ url('entries') }} function.

Anyway: to be honest I would create a different approach in the first place. Creating static URLs in a text field is usually not a good thing. I'm always a fan of the

protect clients against themselves

philosophy so you may want to consider to create a custom field type with autosuggestion or something. SEO wise it could be a bad idea if you clients are able to insert whatever they want and you output too many dead links. Maybe a Relation field could be something for you?

Robin Schambach
  • 19,713
  • 1
  • 19
  • 44
  • So I actually went with your suggestion of just having the client put in the slug of the url. Inside my template I just append the siteUrl onto the front of it. It seems to work across three different languages. – Dan Zuzevich Jul 03 '18 at 10:24