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

Problems with segments #9

Closed
francescomugnai opened this issue May 21, 2019 · 5 comments
Closed

Problems with segments #9

francescomugnai opened this issue May 21, 2019 · 5 comments

Comments

@francescomugnai
Copy link

Hello,

first of all, thank you for this great plugin. It's fantastic!
I think I've a problem with the segments.

This is the situation: I've a site (not yet online) with 2 languages.

  • case 1: example.com/room
    If i pick one of the two languages I get redirect to the homepage (and not to the same page, translated, as expected).
    The url I get is something like: example.com/en?__geom=✪

  • case 1: example.com/room/test
    it works like a charm. I can switch between the translated versions of the same page
    The url I get is something like: example.com/en/room/test?__geom=✪

My link is simple as this:

<li>
       <a href="{{ siteLink.url | addOverrideParam }}">
           {{ siteLink.site }}
       </a>
</li>

My geomate.php file is like this:

return [
    'autoRedirectEnabled' => true,
    'redirectIgnoreAdmins' => false,
    'redirectMap' => [
        'italiano' => 'it',
        'inglese' => '*' 
    ]
];

What do you think? Can you please help me?
Thank you!

@aelvan
Copy link
Contributor

aelvan commented Jul 4, 2019

Hi, sorry for the late reply, overlooked this. Is example.com/room the route to an entry (or other element), or is it just a template path?

@francescomugnai
Copy link
Author

Ciao André, thank you for your reply!
It's a template path.

My scenario is:

  • entries -> fine
  • template paths -> not working

Thanks!

@aelvan
Copy link
Contributor

aelvan commented Jul 8, 2019

Right, that's the intended behavior. Geomate will only know what the url for the other sites are, if the current template has an element with an url for the other sites. If not, it'll fall back to linking to the frontpage of the other sites.

You can either do some conditionals and manually output the urls for template paths, or use singles instead of template paths. I reccommend the last, it's much more flexible.

@amityweb
Copy link

amityweb commented Jul 13, 2019

Same issue here, so I added a check if its an enty, and if its not then create the URLs from the path and site ids (which works), but what happens now is the GeoMate cookie is never created. So when I go to the new site, which has __geom=✪ in the URL, I get my language select popup continuously. The cookie is not created to stop it. Works OK for entries.

Does the cookie only get created if its an entry?

{% if entry is not defined %}
	
	{% set targetUrl =  siteUrl(craft.request.getPath(), siteId=redirectInfo.site.id) %}
	{% set currentUrl =  siteUrl(craft.request.getPath(), siteId=currentSite.id) %}

{% else %}
	
	{% set targetUrl = redirectInfo.url %}
	{% set currentUrl =  currentSite.baseUrl %}

{% endif %}

Full code:

{% set redirectInfo = craft.geomate.redirectInformation() %}

{% if redirectInfo %}
	
	{% set targetSiteSettings = craft.app.globals.getSetByHandle('siteSettings', redirectInfo.site.id) %}
	{% set currentSiteSettings = craft.app.globals.getSetByHandle('siteSettings', currentSite.id) %}
	
	{% set currentCountryFlag = currentSiteSettings.countryFlag.first() %}
	{% set targetCountryFlag = targetSiteSettings.countryFlag.first() %}
	

	<div class="reveal" id="countryRedirectPopup" data-reveal>

		<p>{{ strings('Please select the country version of the website you would like to view')}}</p>
		
		<br/>

		{% if entry is not defined %}
			
			{% set targetUrl =  siteUrl(craft.request.getPath(), siteId=redirectInfo.site.id) %}
			{% set currentUrl =  siteUrl(craft.request.getPath(), siteId=currentSite.id) %}
		
		{% else %}
			
			{% set targetUrl = redirectInfo.url %}
			{% set currentUrl =  currentSite.baseUrl %}
		
		{% endif %}
		
		<a href="{{ targetUrl | addOverrideParam }}"><img src="{{ targetCountryFlag.url }}" width="30" height="20">  {{ redirectInfo.site.name }}</a>
		
		<br/>
		<br/>
		
		<a href="{{ currentUrl | addOverrideParam }}"><img src="{{ currentCountryFlag.url }}" width="30" height="20"> {{ currentSite.name }}</a>
		
		<br/>
		<br/>
		
		<img src="/assets/img/logo" width="200" height="49">

		<button class="close-button" data-close aria-label="Close modal" type="button">
			<span aria-hidden="true">&times;</span>
		</button>

	</div>


{% endif %}

@aelvan
Copy link
Contributor

aelvan commented Feb 14, 2020

This had nothing to do with the original issue, but it looks like you always showed the popup, there's no conditional to check if the user already has selected a site (ie, craft.geomate.isOverridden()). craft.geomate.redirectInformation() will always return information about what site the user should be redirected to, regardless of if he was or not in the past.

Please open a new issue if you think there're additional issues related to this.

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

3 participants