Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Override article form with a URL parameter
Consider this (fictitious) URL:
https://www.example.com/fruit/lemon
The section name is fruit
, the article title is lemon
. The section uses the default
page, and the lemon
article uses the default
form.
I would like to use an additional, alternate form to default
, and be able to specify it from a URL parameter, like this:
https://www.example.com/fruit/lemon?form=cake
Ideally, both URLs should work. The article content will be the same, but the user agent output will be different because the forms do different things.
As an alternative, is there a way I can modify page content to follow this logic: “if the URL parameter form
equals cake
then do A else do B”
Are either of these things possible?
Thanks in advance.
Last edited by gaekwad (2016-04-17 16:17:46)
Offline
Re: Override article form with a URL parameter
You should be able to use adi_gps or rah_gps to retrieve the url variable and store it in a variable, then use that as a tag-in-tag attribute for txp:article
. Something like this:
<txp:variable name="article_form">default</txp:variable>
<txp:adi_gps name="form" quiet="1" />
<txp:if_variable name="form" value="cake">
<txp:variable name="article_form">cake</txp:variable>
</txp:if_variable>
<txp:article form='<txp:variable name="article_form" />' />
I used two separate variable names to avoid giving access to other forms via the url. If you make some mistake later in the form, you don’t inadvertently expose it.
If you have several form types to test against, try using smd_multi_choice (effectively php’s switch/case). That allows you to test directly against an url variable and you can define only the cases you need plus the default.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Override article form with a URL parameter
gaekwad wrote #298641:
“if the URL parameter
form
equalscake
then do A else do B”
You could use smd_if for this. It has the urlvar:
test in the “field” attribute so you could use it to match individual items, or a group of items using in
. Either way, in the enclosing container you have access to {replacement}
style variables that match whatever was in the URL. You can plug those into your article as jakob suggests. Saves arsing about with txp:variables
, though you’d do well to check out smd_if’s filter
attribute in tandem.
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
Re: Override article form with a URL parameter
Perfect – thank you, jakob and Bloke – much appreciated, sirs.
Offline