I have an umbrella project with N apps, all with the same web structure, but different db and possibly language.
Since the templates are all the same, I thought of creating a common app and I’m using templates like this:
defmodule WebEnglish.CategoryHTML do
use WebEnglish, :html
embed_templates "category_html/*", root: Common.Templates.root()
end
...
defmodule WebSpanish.CategoryHTML do
use WebSpanish, :html
embed_templates "category_html/*", root: Common.Templates.root()
end
I’m now having two issues:
I can’t use verified routes from common modules that are not templates, since sigil_p is not available there.
I can use verified routes in templates within common, but what if I need routes in another language/format? ex. ~p"/categories" works, but in WebSpanish this should be ~p"/categorias".
I’m looking at localized routes, but this wouldn’t work either because my understanding is that both categories and categorias would be valid routes in both my web apps.
So I kind of need Router Helpers again, but I know it’s deprecated and I’m looking for an alternative.
What do you think? Thanks!
Ah right. Router helpers would have the same problem, though. Do you separate routers for each language are only one? If you have two then I’m not sure what the answer is here. If you have one then you can still use verified routes.
Can you give an example of how you are hoping a shared template will look? Your whole second question of “what if I need routes in another language” is I guess where I’m also confused.
I think you may want to look how the project I linked does it because I don’t think having one web module per language is the best course of action, even if you are only ever going to have two of them. If you do want to have two, I can’t really think of a better way than creating macros that check which module they are in and return the appropriate routes. This would be a 1-1 macro to routes, though which means basically you’d essentially have a third place to manage routes. Maybe someone else will have a better idea. If I think of anything else I’ll report back!
So, basically, I’d like the helper back As stated before, this works and I know I can use it now, but it’s deprecated and I was wondering if there was an alternative.
Sorry about the misunderstanding with languages: my project has a single template for many frontends. They don’t necessarily have different languages, but they’re deployed separately and have their own db. The only thing in common are templates. Routes may or may not be different for the same entities, that’s why I need separate routers.
After reading the thread I am not sure I understand but let’s kick the can…
I think you don’t necessarily want helpers back but want to be able to write a path in your templates which translates during runtime to an URL depending on certain criteria.
Have a look at GitHub - BartOtten/routex. Unlike native verified routes, Routex Verified Routes does support branching. As Routex is extension based, I am quite sure there is a combination of extension which will support your use case.
Demonstration
of single path in template with variable path during runtime