Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2016-03-10 16:38:08

giampablo
Member
From: Italy
Registered: 2008-07-17
Posts: 86
Website

Advice on calling a different form according to article id's

In a simple e-commerce setup, selling services, I am using Shopify BuyButton.
Each service is described in an article page and a complementary column should display the related BuyButton, whose script is contained in his own form.

So, I have let’s say 10 articles for services and 10 forms for BuyButtons.

I could simply use these tags (and it works):

<txp:if_article_id id="1">
<txp:output_form form="buybutton_1" />
</txp:if_article_id>
<txp:if_article_id id="2">
<txp:output_form form="buybutton_2" />
</txp:if_article_id>
...
<txp:if_article_id id="10">
<txp:output_form form="buybutton_10" />
</txp:if_article_id>

Given the textpattern flexibility I am sure a suitable solution for getting the same result exists
(I am thinking to txp:variable tag, for example, with some txp:else )
but I am not able to find where to start with.
Maybe there are other methods that I cannot even imagine.

Any help?
Thanks guys.

Offline

#2 2016-03-10 17:06:30

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

Re: Advice on calling a different form according to article id's

If your form names match article ids, call just

<txp:output_form form='buybutton_<txp:article_id />' />

Otherwise, store form names in some custom field (say, buybutton) and call

<txp:output_form form='<txp:custom_field name="buybutton" />' />

Edit: or, if you have only few forms, call this

<txp:if_article_id id="1,3,5,7,9">
	<txp:output_form form="odd" />
<txp:else />
	<txp:output_form form="even" />
</txp:if_article_id>

Last edited by etc (2016-03-10 17:12:00)

Offline

#3 2016-03-10 17:31:18

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

Re: Advice on calling a different form according to article id's

You could also use the “override form”.


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

Offline

#4 2016-03-10 17:37:03

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: Advice on calling a different form according to article id's

giampablo wrote #298213:

Given the textpattern flexibility

Another way might be to work with the article’s “Override form” setting (choose the appropriate button form here), and for displaying the texts apply allowoverride="0" in the article tags.

Edit: Yiannis was faster :)

Last edited by uli (2016-03-10 17:37:44)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#5 2016-03-10 17:49:47

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

Re: Advice on calling a different form according to article id's

colak wrote #298215:

You could also use the “override form”.

uli wrote #298216:

Another way might be to work with the article’s “Override form” setting (choose the appropriate button form here), and for displaying the texts apply allowoverride="0" in the article tags.

Too much overlap, imo

Offline

#6 2016-03-10 17:58:59

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: Advice on calling a different form according to article id's

etc wrote #298217:

Too much overlap, imo

Valid point. I tought of looking up of form names and typos.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#7 2016-03-10 18:51:25

giampablo
Member
From: Italy
Registered: 2008-07-17
Posts: 86
Website

Re: Advice on calling a different form according to article id's

Thanks everybody, but… can you elaborate a bit more about “Override form”?

If I well understand, I should set each article with the appropriate button form using the Override form selection under Advanced Options, right?
Then, since I use <txp:article form="singolo_corso" /> I should change to <txp:article form="singolo_corso" allowoverride="0" /> but I am lost after that.
How can I display the text/button in a different column?
I’m curious about it, since I never used the “Override form” in articles.

Offline

#8 2016-03-11 13:39:07

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: Advice on calling a different form according to article id's

Hi giampablo,
I don’t know exatly how the shopify button code works but as far as I can see you probably don’t need to change the whole code for each article. Can’t you change some data attributes or button ID with txp article tags?

Last edited by NicolasGraph (2016-03-11 17:49:27)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#9 2016-03-11 14:54:26

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

Re: Advice on calling a different form according to article id's

NicolasGraph wrote #298226:

Can’t you change some data attributes or button ID width txp article tags?

+1. This way you avoid code redundancy, getting things easier to maintain. Putting article-specific shopify data in custom fields might suffice.

Offline

#10 2016-03-12 16:52:39

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: Advice on calling a different form according to article id's

giampablo wrote #298220:

If I well understand, I should set each article with the appropriate button form using the Override form selection under Advanced Options, right?

Yep.

How can I display the text/button in a different column?

You’d have to place a second article tag somewhere. A thing I (as a graphic designer) don’t think about too much but causes the redundancy that Oleg/etc (as a programmer) criticised.

Override form was one of the things that made me say Wow! re Textpattern’s versatility when I became acquainted with TXP. It’s enough to simply put a plain short article tag somewhere, no form attribute required and nothing, and TXP uses the default form. You can, however, use a different design/data arrangement/data selection and specify a form of your liking on page/template level. Moreover, you can let an author override this choice on single article basis (override form on the Write panel) and make “multicoloured” article lists from predefined layouts if s/he likes to, and yet can then again let the coder have the final say by using allowoverride="0".


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#11 2016-03-13 09:39:02

giampablo
Member
From: Italy
Registered: 2008-07-17
Posts: 86
Website

Re: Advice on calling a different form according to article id's

In my case, I picked the simplest solution by Oleg,
<txp:output_form form='buy_<txp:article_id />' />
since I can just name my forms according to article ids (buy_1, buy_2…).

But wow Uli! You just opened a whole new world to me. For instance, if I want an article list with alternate layouts, (i.e. article picture on the left side and body text on the right, then body on the left and article picture on the right, and so on… ) I can use “override form” on single article basis, with a predefined layout for the “left_picture” arrangement and an alternate layout for “right_picture” arrangement. Simple!
Override form is a hidden, really underestimated, little function in TXP.

@Nicolas, thank you for submitting your idea. Seems a viable solution, too. After looking at shopify code, I need 4 (maybe 5) custom-fields with article-specific shopify data attributes (as per brilliant Oleg contribution). At the moment I have less than 10 products/buttons. When/if product offers will be more (and more difficult to maintain) that is the route I will take.

Thanks everybody.

Last edited by giampablo (2016-03-13 09:40:04)

Offline

#12 2016-03-13 13:34:59

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: Advice on calling a different form according to article id's

giampablo wrote #298234:

@Nicolas, thank you for submitting your idea. Seems a viable solution, too. After looking at shopify code, I need 4 (maybe 5) custom-fields with article-specific shopify data attributes (as per brilliant Oleg contribution). At the moment I have less than 10 products/buttons. When/if product offers will be more (and more difficult to maintain) that is the route I will take.

If you would take this route consider the idea to use not only custom fields but also regular fields like title, url title and article image if you can to populate the data attributes.


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

Board footer

Powered by FluxBB