Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 Yesterday 08:14:37

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,893
Website GitHub

Adding a custom attribute to a custom permlinkhandler?

Another plugin knot I’ve got myself tied up in …

I have a mini plugin that reads a language code prefix from the url, i.e. /en/section/url-title is handled by textpattern as /section/url-title and en is saved in a variable. It also automatically adds the currently set language prefix to functions that output permlinks using the custom_url_func pref.

For the language switcher, I need to override the automatically set current language. Initially I tried a simple search and replace using trim and replace or a txp:evaluate wrapper (or even a search/replace plugin function) but was puzzled to get no results. After some dmp()-ing of the variables, I see that although I can see the current language and target language variables, I have no output to act on from txp:permlink and co. It seems that this could be because the plugin load order is set to 4 (to allow the custom_url_func function to cut in).

What I’d really like to do is add a global lang attribute to the custom permlink handler so that I can add lang="de" to txp:permlink and the other functions, but my attempts to register a global attribute as Oleg describes here were unsuccessful. What am I missing here, for example is there a trick to tweaking the processing order/cycle that I can use?

For now I got around it by making an entirely separate plugin tag that grabs and dissects the REQUEST_URI and then rebuilds the respective link with the desired language, but it’s essentially recreating the wheel.


TXP Builders – finely-crafted code, design and txp

Offline

#2 Yesterday 08:57:38

etc
Developer
Registered: 2010-11-11
Posts: 5,378
Website GitHub

Re: Adding a custom attribute to a custom permlinkhandler?

jakob wrote #339655:

What I’d really like to do is add a global lang attribute to the custom permlink handler so that I can add lang="de" to txp:permlink and the other functions, but my attempts to register a global attribute as Oleg describes here were unsuccessful. What am I missing here, for example is there a trick to tweaking the processing order/cycle that I can use?

Could you provide more details here? What have you tried and what the global lang is expected to do?

For now I got around it by making an entirely separate plugin tag that grabs and dissects the REQUEST_URI and then rebuilds the respective link with the desired language, but it’s essentially recreating the wheel.

Probably (at least in 4.9) you can reduce the code to extracting lang value and then leaving links generation with core:

<txp:page_url root='<txp:variable name="lang" />/'>
    <txp:permlink />
    ...
    another <txp:permlink />
</txp:page_url>

Offline

#3 Today 09:53:45

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,893
Website GitHub

Re: Adding a custom attribute to a custom permlinkhandler?

etc wrote #339657:

Could you provide more details here? What have you tried and what the global lang is expected to do?

Calling it a global attribute is probably wrong as I only want(ed) to add it to txp:permlink and corresponding permlink-like tags with the link attribute in the hope that I could act on the attribute from directly in the permlink/pagelink handler. As I’ve discovered while assembling this plugin into a more coherent shape from earlier smaller plugins, it’s not vitally important. It also doesn’t use Textpattern’s internal lang tag/variable, so is perhaps better to keep separate.

FWIW, jcr_langprefix is what I have so far. (For the one or two people who have used an earlier version of this, note that this is a continuation but not a drop-in replacement of the earlier plugin. Some tag names have changed, as have the settings. See the help and changelog.)


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB