2012-06-03 15:22:10

etc
Plugin Author
mu
Real name: Oleg
Known languages: ru, fr, en, google.translate(*)
Website

etc_url: rewrite some parts of url

When paginating all kinds of lists, one often needs to append (or modify) some parameters to an url, all by preserving the other parameters. I have found no lightweight plugin that does it, so here is etc_url.

This tiny plugin will take an url and append (or rewrite) some query string to it, like this:

<txp:etc_url url="http://my.web.site/section/tag/?q=etc&pg=2" query="pg=3" />

will produce http://my.web.site/tag/?q=etc&pg=3 in /section/title permalink mode. That’s all!

Currently, semantic txp parameters (like section or category) do receive no special treatment in clean mode, i.e. any only ?query part of url is parsed. Some future version could do it if needed.

Attributes

  • url: url to rewrite, default is the current page url.
  • query: &-separated list of tokens to append/modify, like this: key1=val1&key2&key3=val3. If val is not set, the key will be removed from url.
  • custom: whether url should be parsed.

History

Version 0.1: initial release.
Version 0.2: respects all permalink modes. Added custom attribute.

Last edited by etc (2013-04-09 09:17:12)


etc_[ query | search | link_to | pagination | date | url ]

Offline

 

2012-06-03 20:59:05

maruchan
Member
mu
Real name: Marc Carson
From: Ukiah, California
Known languages: EN-US, JP
Website

Re: etc_url: rewrite some parts of url

Very good of you to release this, etc. I will look into the pagination method. I still need to understand xpath, but it is something I want to do sooner than later. :-)

Offline

 

2012-06-04 13:56:39

etc
Plugin Author
mu
Real name: Oleg
Known languages: ru, fr, en, google.translate(*)
Website

Re: etc_url: rewrite some parts of url

maruchan wrote:

Very good of you to release this, etc.

Thank you for your welcome, and have fun with xpath! It is just another language for DOM traversing, with very similar to jQuery or CSS syntax, that is understood by php (and now by TXP:-) too.


etc_[ query | search | link_to | pagination | date | url ]

Offline

 

2012-06-12 09:12:44

etc
Plugin Author
mu
Real name: Oleg
Known languages: ru, fr, en, google.translate(*)
Website

Re: etc_url: rewrite some parts of url

Version 0.11 : added queue attribute, see this tip for usage example. Removed

Last edited by etc (2013-04-09 09:17:58)


etc_[ query | search | link_to | pagination | date | url ]

Offline

 

2013-04-09 09:19:42

etc
Plugin Author
mu
Real name: Oleg
Known languages: ru, fr, en, google.translate(*)
Website

Re: etc_url: rewrite some parts of url

Version 0.2: respects permalink modes.

Edit: it can also create links to articles filtered by multiple criteria that will fit any permalink mode:

<txp:etc_url url="" query="c=novels&author=Jack London&month=1903" />

Last edited by etc (2013-04-09 12:16:24)


etc_[ query | search | link_to | pagination | date | url ]

Offline

 

2013-05-21 10:04:35

kees-b
Member
êta
Real name: kees brandenburg
From: middelburg, nl
Known languages: nl, en, fr
Website

Re: etc_url: rewrite some parts of url

Hi, can I use etc_url for constructing an url from the content of a custom field?

Example:

In the custom field: two words
The url I want: http://sitename.com/section/two-words The section is not the same as the article itself, no need to generate it dynamicly for this use.
The url rewriting should follow the same rules as textpattern uses to generate an url from an article title. This means: words need to be stripped from diacritics, capitals removed, connected by a dash.

Another more sophisticated approach might be:

1: read the contents of the custom field
2: look for an article with the same title
3: if it exists: output the url to use it as a link

But I probably need another plugin for that.

-kees

Offline

 

2013-05-21 10:48:22

etc
Plugin Author
mu
Real name: Oleg
Known languages: ru, fr, en, google.translate(*)
Website

Re: etc_url: rewrite some parts of url

Hi,

I don’t think you need a plugin for this. If your custom field is called, say, link, try

<txp:variable name="link"><txp:php>
	global $thisarticle;
	echo stripSpace($thisarticle['link'], 1);
</txp:php></txp:variable>

<a href='/section/<txp:variable name="link" />'><txp:custom_field name="link" /></a>
<!-- will generate something like <a href='/section/two-words'>Two Words</a> -->

Use etc_url only if you need to respect the site url mode:

<txp:etc_url url="" query='s=<txp:variable name="link" />' />
<!-- will generate something like <a href='http://sitename.com/?s=two-words'>Two Words</a> in messy mode -->

etc_[ query | search | link_to | pagination | date | url ]

Offline

 

2013-05-21 11:05:51

kees-b
Member
êta
Real name: kees brandenburg
From: middelburg, nl
Known languages: nl, en, fr
Website

Re: etc_url: rewrite some parts of url

etc wrote:

Hi,

I don’t think you need a plugin for this. If your custom field is called, say, link, try

<txp:variable name="link"><txp:php>
	global $thisarticle;
	echo stripSpace($thisarticle['link'], 1);
</txp:php></txp:variable>

<a href='/section/<txp:variable name="link" />'><txp:custom_field name="link" /></a>
<!-- will generate something like <a href='/section/two-words'>Two Words</a> -->

Thanks! I allready thought this should be possible with txp:variable. I’ll give it a try.

-k

Offline

 

Yesterday 19:31:31

kees-b
Member
êta
Real name: kees brandenburg
From: middelburg, nl
Known languages: nl, en, fr
Website

Re: etc_url: rewrite some parts of url

you’re suggested solution with txp:variable does the trick perfectly!

thanks!

-kees

Offline

 

Powered by FluxBB