Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a specific page link depending of the _locale ? #30

Open
david-vde opened this issue Jan 21, 2021 · 1 comment
Open

Generate a specific page link depending of the _locale ? #30

david-vde opened this issue Jan 21, 2021 · 1 comment

Comments

@david-vde
Copy link

Hello

I'm trying to generate a link on a custom page (not a cmspage) to point on a cmspage.

I do this :

<a href="{{ path('orbitale_cms_page', {slugs: 'my-page-slug'}) }}">{% trans %}menu.my_page{% endtrans %}</a>

it works perfectly. But. I'm creating a multi-language website. I can't figure out how to deal with the _locale.

As in the database the slug changes depending the language, currently I have to manually, make a condition, to check the current locale and take the good slug, but, obviously this is not a good way to do.

How am I supposed to deal with that? And by the way, I can't find any way to links 2 pages records of different language.

Thank you

@Pierstoval
Copy link
Member

Pierstoval commented Jan 22, 2021

Generating URLs isn't the role of the CmsBundle, it's done with the Symfony Routing component.

Usually, when you use path() or url() in Twig, the _locale parameter is automatically set to the current locale.

Let's say your route path is /{_locale}/some-page, if you are on the /en/some-page page, the _locale parameter will be en, and will automatically be set when generating URLs in your views.

There is currently no way to generate a link for a specific page in your views: as pages are dynamic, you either have to hard-code them (and make sure the Page object exists in the database, and this is your job, not the bundle's one), or find a way to create some kind of "CMS router" that will fit your needs.

You could also create your own Doctrine entities that would have relationships with the Page entity, either via ManyToOne or ManyToMany, and with something like that, you could definitely automatize the process of generating links for these relationships.

Does it help? 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants