Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2024-10-05 16:35:33

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,081
Website GitHub Mastodon Twitter

[SOLVED] oui_cookie and site/page languages

I’m trying to work out how to use cookies in order to present english, greek, or both languages to a page. The logic is below but I just can’t turn my head around it. I’m sure it’s simple and I’ll possible wake up at 2am with a solution which I will forget by the time I wake up, so any help would be appreciated.

<txp:oui_cookie name='<txp:variable name="sitename" />_<txp:variable name="lang_iso" />' duration='<txp:variable name="cookielife" />' values="yes" />
<txp:oui_if_cookie name="lang_en">
hide Greek text
delete cookie lang_el if it exists
</txp:oui_if_cookie>
<txp:oui_if_cookie name="lang_el">
hide English text divs
delete cookie lang_en
</txp:oui_if_cookie>
<txp:oui_if_cookie not>
no cookie and show all divs
delete cookie lang_el
delete cookie lang_en
</txp:oui_if_cookie>

Also, I’m not sure how to delete a cookie from the front end. The help file says.

delete
Value: string; none by default.An GET/POST parameter value used to delete the cookie.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#2 2024-10-07 03:50:53

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,081
Website GitHub Mastodon Twitter

Re: [SOLVED] oui_cookie and site/page languages

I slept over it and realised that there is a simpler way which I can still not do as I don’t know how to provide a link to delete a cookie.

The idea.

The form

<txp:oui_cookie name="lang_el" duration="1 month" values="yes" />
<txp:oui_if_cookie name="lang_el">
<txp:if_yield name="txt"><txp:yield name="txt"></txp:if_yield>
<txp:else />
show delete cookie  to revert to English using a link
</txp:oui_if_cookie>

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2024-10-07 06:00:48

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,435
Website GitHub

Re: [SOLVED] oui_cookie and site/page languages

To delete a cookie, I thought you just supplied <txp:oui_cookie name="your cookie" delete />?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2024-10-07 16:19:12

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,081
Website GitHub Mastodon Twitter

Re: [SOLVED] oui_cookie and site/page languages

Bloke wrote #337964:

To delete a cookie, I thought you just supplied <txp:oui_cookie name="your cookie" delete />?

Hi Stef,

Thanks so much for the response.

I thought that it was that simple but does not work! Unless I’m missing something, To test it, I added <p><txp:oui_cookie name="accept_NeMe_youtube" delete /></p> under the youtube cookie warning on NeMe’s front page but nothing shows, either with the cookies accepted, or not.

Also tried <p><a href="<txp:oui_cookie name="accept_NeMe_youtube" delete />">#</a></p> just in case but that only parses <p><a href="">#</a></p>.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#5 2024-10-07 16:57:49

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,435
Website GitHub

Re: [SOLVED] oui_cookie and site/page languages

colak wrote #337967:

I added <p><txp:oui_cookie name="accept_NeMe_youtube" delete /></p> under the youtube cookie warning on NeMe’s front page but nothing shows

What do you mean “nothing shows”? The tag doesn’t output anything.

I just tested it like this on my site with the 1.0.0-beta4 plugin:

  1. Created an article called Cookie Test.
  2. Added <oui::cookie name="accept_NeMe_youtube" value="yup" /><br>Value=<oui::cookie name="accept_NeMe_youtube" /> to the page.
  3. Viewed the article.

Result:
Value=yup

I checked the existence of the cookie in the Inspector’s Network -> Cookie panel. It was there.

Next:

  1. Edited the article called Cookie Test so the code is: <oui::cookie name="accept_NeMe_youtube" delete /><br>Value=<oui::cookie name="accept_NeMe_youtube" />.
  2. Viewed the article.

Result:
Value=

i.e. the cookie has gone. The web inspector confirms it’s not there any more.

Are you sure you’re not (re)setting the cookie elsewhere in another page template?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#6 2024-10-08 00:58:15

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,081
Website GitHub Mastodon Twitter

Re: [SOLVED] oui_cookie and site/page languages

Apologies as it appears to be my bad description in what I’m looking for. I’ll try it again.

I’m looking for a link that if clicked, a particular cookie is deleted, similarly to the /?accept_NeMe_youtube=yes link which, if clicked, serves the cookie and loads youtube videos.

The context is not however the videos but the articles I have in English and Greek.

I’m trying to

  1. load English content by default with a cookie link to view the article in Greek
  2. If the cookie link is clicked, the english content is replaced by the Greek content, with a cookie delete link, that deletes the cookie and loads the cookieless English content.

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#7 2024-10-08 10:33:58

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,435
Website GitHub

Re: [SOLVED] oui_cookie and site/page languages

Then I expect it’s a limitation of the cookie spec. Is it possible to set/alter more than one cookie in a single header call? I don’t think it’s doable.

Some browsers allow a comma separated list to set. But I don’t know if you can set and delete in the same request.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#8 2024-10-08 14:47:57

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,081
Website GitHub Mastodon Twitter

Re: [SOLVED] oui_cookie and site/page languages

Bloke wrote #337972:

Then I expect it’s a limitation of the cookie spec. Is it possible to set/alter more than one cookie in a single header call? I don’t think it’s doable.

Some browsers allow a comma separated list to set. But I don’t know if you can set and delete in the same request.

I thought as much…Thanks. I’ll have to figure another way.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#9 2024-10-12 04:17:45

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,081
Website GitHub Mastodon Twitter

Re: [SOLVED] oui_cookie and site/page languages

This is what I was thinking about, but I cannot make it work in the context of the plugin.

<txp:php>
// Check if the cookie exists and delete it
if (isset($_GET['delete_cookie'])) {
    setcookie("lang_el", "", time() - 3600, "/"); // Delete the cookie
}
</txp:php>
<a href="/?delete_cookie=trueDelete">Cookie 'lang_el'</a>

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#10 2024-10-12 08:34:13

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,435
Website GitHub

Re: [SOLVED] oui_cookie and site/page languages

Strange. That idea should work. But you shouldn’t need the $_GET or in fact the PHP at all, as it should be possible with the <txp:page_url /> tag.

Edit: btw, is the php code on the home page, cos your anchor is targeting that. If you remove the preceding slash it’ll work on the current page.

Last edited by Bloke (2024-10-12 08:35:49)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#11 2024-10-12 14:08:56

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,435
Website GitHub

Re: [SOLVED] oui_cookie and site/page languages

colak wrote #337999:

Note that the test article is in draft status.

That is probably why. Not sure if you hit the link whether it will actually run the code. Try adding echo "hello greek"; inside the conditional if block and see if it shows up when you hit the cookie delete link.

Edit: damn I think I hit Edit instead of Quote on your post because it’s disappeared. The original post is here, sorry:

I created a test article where I added the following:

notextile. <txp:oui_cookie name="lang_el" duration="1 day" values="yes" />
<txp:oui_if_cookie name="lang_el">
<txp:php>
if (isset($_GET['delete_cookie'])) {
    setcookie("lang_el", "", time() - 3600, "");
}
</txp:php>

 <p><a rel= "nofollow noindex noodp noydir noarchive nocache" href="?delete_cookie=trueDelete">View English version</a></p>

 <p lang="el">Λορεμ ιπσθμ δολορ σιτ αμετ, qθι εα πθρτο προμπτα δελεcτθσ, vιξ φερρι λαθδεμ ποστθλαντ εα, μθνδι ανcιλλαε ιδ εοσ. Vιξ ατ δεβετ πηαεδρθμ σενσιβθσ, ατqθι εραντ ομιτταντθρ ετ δθο, πρι ιδqθε ατqθι ιδ. Cετεροσ cονcεπταμ νε περ. Qθο εα ιδqθε αθγθε, qθι εα cηορο εσσεντ. Διcιτ προμπτα ετ σεδ, εθμ cετερο σθαvιτατε vολθπτατθμ cθ.</p>

 <txp:else />

 <p><a rel= "nofollow noindex noodp noydir noarchive nocache" href="?lang_el">View Greek version</a></p>

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum egestas scelerisque eros, quis porta diam blandit at. Sed ornare neque turpis, sed porttitor nulla bibendum nec. Nam id tellus quam. Ut at felis sed nisl auctor tempus eu et quam. Integer et arcu sit amet lectus tristique mollis vel finibus. 

 </txp:oui_if_cookie>

As expected the article shows the link to view the Greek version, and the latin character lorem ipsum.

For some reason, even after deleting the foreslash, the link points to <txp:site_url />?lang_el and the cookie is not set.

Note that the test article is in draft status.

Also I tried:

notextile. <txp:oui_cookie name="lang_el" duration="1 day" values="yes" />
<txp:oui_if_cookie name="lang_el">
<txp:php>
if (isset(['delete_cookie']) {
    setcookie("lang_el", "", time() - 3600, "");
}
</txp:php>

which yielded no results either

Last edited by Bloke (2024-10-12 14:14:47)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#12 2024-10-12 14:13:05

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,081
Website GitHub Mastodon Twitter

Re: [SOLVED] oui_cookie and site/page languages

I created a test article where I added the following:


notextile. <txp:oui_cookie name="lang_el" duration="1 day" values="yes" />
<txp:oui_if_cookie name="lang_el">
<txp:php>
if (isset($_GET['delete_cookie'])) {
    setcookie("lang_el", "", time() - 3600, "");
}
</txp:php>

 <p><a rel="nofollow noindex noodp noydir noarchive nocache" href="?delete_cookie=trueDelete">View English version</a></p>

 <p lang="el">Λορεμ ιπσθμ δολορ σιτ αμετ, qθι εα πθρτο προμπτα δελεcτθσ.</p>

 <txp:else />

 <p><a rel= "nofollow noindex noodp noydir noarchive nocache" href="?lang_el=yes">View Greek version</a></p>

Lorem ipsum dolor sit amet, consectetur adipiscing elit. 

 </txp:oui_if_cookie>

As expected the article shows the link to view the Greek version, and the Latin character lorem ipsum.

On clicking the ?lang_el=yes link, the cookie is set as expected and the Greek version is shown with the delete link. Clicking the delete link however, does not delete the cookie, and the Greek version is maintained.

I also tried:


notextile. <txp:oui_cookie name="lang_el" duration="1 day" values="yes" />
<txp:oui_if_cookie name="lang_el">
<txp:php>
if (isset(['delete_cookie']) {
    setcookie("lang_el", "", time() - 3600, "");
}
</txp:php>

which yielded no results either


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB