Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Changing the article form using the URL
I’m using /section/title
as my url format, like this:
http://example.com/section/title
I’d like to be able keep the article assigned to the section, avoid duplicating the content, and use a different article form. I’d like to be able to do this with a URL:
http://example.com/section/title?foo=bar
http://example.com/section/title?form=formname
Is such a thing possible? I can use this:
- http://example.com/?id=123&s=section
…but is there another way that retains the URL format (largely or completely)?
Thanks in advance, compadres.
Edit: I’ve found this which may well solve my problem. TBC.
Last edited by gaekwad (2014-02-26 11:53:01)
Offline
Re: Changing the article form using the URL
gaekwad wrote #279288:
is there another way that retains the URL format (largely or completely)?
If you want to keep clean URLs you could take advantage of the fact that Txp ignores anything after the article title. To the CMS, site.com/section/your-article
is the same as site.com/section/your-article/rod/jane/and/freddy
.
So using a lick of PHP in your Page template to compare the actual, expected article URL with the one the server delivers to the page gives us the leftovers, which we can pop off the end to get a value you can use for whatever nefarious purposes you desire. In this case, any text after a slash after the url-title will be assigned to a txp:variable called url_form
.
<txp:php>
global $variable;
// The current URL, split at slash
$uri = serverSet('REQUEST_URI');
$uri_parts = explode('/', $uri);
// What Txp expects the current article to be
// (only works in individual article context)
$article_parts = array(
'',
section(array()),
article_url_title(array())
);
// Find the difference between the two
$form = array_diff($uri_parts, $article_parts);
// Assign to variable
$variable['url_form'] = ($form) ? array_pop($form) : 'default';
</txp:php>
Then you can validate it is one of your pre-determined, allowable Form names using <insert plugin or code here> and stuff the result in the <txp:article>
tag’s form
attribute.
There might be a better way to do it, perhaps using <txp:page_url />
or some clever URL wrangling but off the top of my head, that should give you something to work on.
EDIT: it’s not very robust so any query string parameters would need lopping off first.
Last edited by Bloke (2014-02-26 20:01:15)
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