Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2010-04-19 20:28:06
- Scott Girvan
- Member
- Registered: 2010-04-14
- Posts: 10
Use certain form if certain category?
Hi,
Having a brain fart.
I have a section called TIPS.
The site has 2 different types of tips, Video Tips and Not Video Tips.
I have the categories videoTips & NormalTips.
I write an article, assign it to the TIPS section and one of the 2 categories.
On the main tips section page I have :
<txp:if_individual_article>
<txp:if_category name="NormalTips">
<txp:article_custom form="normalTipsOutput" pgonly="0" section="tips" />
<txp:else />
<txp:article_custom form="videoTipsOutput" pgonly="0" section="tips" />
</txp:if_category>
<txp:else />
<txp:article_custom form="tipsMainView" pgonly="0" section="tips" />
</txp:if_individual_article>
Aint working. Go figure. I suck. Would you please point me towards a solution? Better yet, could you share with me a solution?
Merci bigtime
Scott.
Code format -Gocom
Last edited by Gocom (2010-04-19 21:18:42)
Offline
#2 2010-04-19 20:33:38
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Use certain form if certain category?
You need if_article_category.
Are you trying to display an individual article using article_custom? That’s not possible, you need <txp:article />
instead. But I may misunderstand your intention ;)
Offline
#3 2010-04-19 20:59:27
- Scott Girvan
- Member
- Registered: 2010-04-14
- Posts: 10
Re: Use certain form if certain category?
Els, thank you. Awesome. So much to learn.
While I’m on the subject of not having a clue – I use article_custom alot. Should I? What’s the difference between the two? In the above context they both give me the same result. Odd.
So I just did some homework and
<txp:article_custom form="normalTipsOutput" pgonly="0" section="tips" />
isn’t necessary.
<txp:article form="normalTipsOutput" />
should work because article knows that we are in the Tips section.
True?
Formated code -Gocom
Last edited by Gocom (2010-04-19 21:17:01)
Offline
Re: Use certain form if certain category?
Let the tag references tell you:
Other is strictly context sensitive, supports pagination and URL filters, while other doesn’t and is used as non-context global listings.
Plus article_custom can not handle individual articles. If you want to show individual articles you need (as you seem to want to, atleast according your conditionals):
<txp:article />
instead custom listing tag.- And correct conditional tag that is used with articles not category pages:
<txp:if_article_category>
.
According these facts that can be gathered just by looking at Tag Reference, we can make up something like:
<txp:if_individual_article>
<txp:if_article_category name="NormalTips">
<txp:article form="normalTipsOutput" />
<txp:else />
<txp:article form="videoTipsOutput" />
</txp:if_article_category>
<txp:else />
<txp:article form="tipsMainView" />
</txp:if_individual_article>
PS. to prevent unwanted malfunction you shouldn’t be using capitalized letters in category names. Especially when the names are used in URLs. Category titles on other hand can use anything.
Offline
#5 2010-04-19 21:16:09
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Use certain form if certain category?
Yes, in your case they give you the same result. But <txp:article />
is context sensitive, in individual article context it wil display an individual article, on a section or category list page it displays a list of articles from that section or category, on a search results page it displays search results… well, you get the idea ;)
<txp:article_custom />
is great to display articles from other sections than the current section, article lists on an individual article page, in short, display anything anywhere.
So if you want to display (on an individual article page) your individual article and a list of for instance related articles, you must use <txp:article_custom />
for the list because <txp:article />
in that context will only display the individual article.
Your last article_custom tag could be replaced by <txp:article form="tipsMainView" />
and it would display exactly the same. BTW you can leave out pgonly="0"
because 0
is the default value for that attribute.
Edit: late again ;)
Last edited by els (2010-04-19 21:16:30)
Offline
#6 2010-04-19 22:24:34
- Scott Girvan
- Member
- Registered: 2010-04-14
- Posts: 10
Re: Use certain form if certain category?
Thank you both very much. This really clears things up. The Tag Reference is fantastic, my problem is not knowing what to search for and therefore I ask here. I truly appreciate this tutorial. Your posts have taught me a lot.
Scott.
Offline
Re: Use certain form if certain category?
Scott Girvan wrote:
The Tag Reference is fantastic, my problem is not knowing what to search for and therefore I ask here.
That’s the #1 right thing to do in such situation. The support forum and community is here to help those that are in need. If you have something that requires assistance, just ask :-)
Offline
#8 2010-04-22 11:25:32
- Gallex
- Member
- Registered: 2006-10-08
- Posts: 1,315
Re: Use certain form if certain category?
Gocom wrote:
<txp:if_individual_article>
<txp:if_article_category name="NormalTips">
<txp:article form="normalTipsOutput" />
<txp:else />
<txp:article form="videoTipsOutput" />
</txp:if_article_category>
<txp:else />
<txp:article form="tipsMainView" />
</txp:if_individual_article>
but if i have more than two different type of tips, how then the code should look like?
Offline
Re: Use certain form if certain category?
I believe you can use rah_output_section_form with categories too by using the attribute type="category"
. Have a look at the example to see how the basic principle works.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Use certain form if certain category?
jakob wrote:
I believe you can use rah_output_section_form with categories too by using the attribute
type="category"
. Have a look at the example to see how the basic principle works.
But not within individual articles, only with category pages :-)
Gallex wrote:
but if i have more than two different type of tips, how then the code should look like?
Then you can stack more conditionals.
<txp:if_article_category name="category_1">
<txp:article form="category_1" />
</txp:if_article_category>
<txp:if_article_category name="category_2">
<txp:article form="category_2" />
</txp:if_article_category>
<txp:if_article_category name="category_[...]
Or if you have forms named according the category names (form_category_1, form_category_2 […]), you can call the forms by using the category name as the form
value.
<txp:article form='form_<txp:category1 />' />
Offline
Re: Use certain form if certain category?
Gocom wrote:
<txp:if_individual_article>
<txp:if_article_category name="NormalTips">
<txp:article form="normalTipsOutput" />
<txp:else />
<txp:article form="videoTipsOutput" />
</txp:if_article_category>
<txp:else />
<txp:article form="tipsMainView" />
</txp:if_individual_article>
Gallex wrote:
but if i have more than two different type of tips, how then the code should look like?
In this case, you can nest if_article_category
, like this:
<txp:if_individual_article>
<txp:if_article_category name="NormalTips">
<txp:article form="normalTipsOutput" />
<txp:else />
<txp:if_article_category name="SuperTips">
<txp:article form="SuperTipsOutput" />
<txp:else />
<txp:article form="videoTipsOutput" />
</txp:if_article_category>
</txp:if_article_category>
<txp:else />
<txp:article form="tipsMainView" />
</txp:if_individual_article>
But after a few categories, the code begins to become rather difficult to read and maintain. If every TXP conditional could accept an elif
tag, it would be much easier.
Another option is to just use conditionals, but not nested (edit: as Gocom showed in previous post). But again, difficult to maintain, and that probably brings some performance penalties (wonder which is worst for performance: parsing nested conditionals of the same type or just testing each condition, even when just one will be True).
But then, there is another practice that makes it easier, imho, to do maintainance work… tags in tags to the rescue!
<txp:if_individual_article>
<txp:article form='tip_<txp:category1 />' />
<txp:else />
<txp:article form="tip_" />
</txp:if_individual_article>
That’s the basic, raw concept.
A more “advanced” version could be:
<txp:if_individual_article>
<txp:if_article_category number="1">
<txp:article form='tip_<txp:category1 />' />
<txp:else />
<txp:article form='tip_default' />
</txp:if_article_category>
<txp:else />
<txp:article form="tip_" />
</txp:if_individual_article>
And a more flexible one could be:
<txp:if_individual_article>
<txp:if_article_category number="1">
<txp:article>
<txp:output_form form='tip_<txp:category1 />' />
</txp:article>
<txp:else />
<txp:article form='tip_default' />
</txp:if_article_category>
<txp:else />
<txp:article>
<txp:output_form form='tip_<txp:category1 />' />
<!-- benefit: on an article list, you will be able to render each post using a category-specific form -->
</txp:article>
</txp:if_individual_article>
Edit: Gocom was faster.
Last edited by maniqui (2010-04-22 15:31:54)
Offline
Pages: 1