Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Boolean check for previous, next and related articles
I’m building a conditional with a variable to check for the previous article, the next article and related articles. Here’s the workflow: if there is a one or more of i) previous article, ii) next article or iii) related articles, do stuff.
I’m using variables, and I would like to keep the content of each variable to a minimum. Perhaps this is a false economy but it makes sense in my brain.
I can create a variable that checks for related articles and sets the variable to 1
if there are related articles:
<txp:variable name="body_content_article_related_audit" value='<txp:related_articles form="audit" limit="1" />' />
The audit
form comprises:
1
Easy enough, and it works: my variable value is small in size. Great. For completeness, I’d like to set two more variables relating to the previous and next articles, again setting a 1
if possible. This I cannot figure out. I can use link_to_prev
and link_to_next
to set my variable value, but that includes a complete HTML link. The prev_title
and next_title
tags provide a shorter string for my variable, but it’s still not perfect; yes, I can check to see if the there is something set in the variable, but I can’t do an exact check against it (i.e., <txp:if_variable name="body_content_article_prev_audit" value="1">stuff<txp:else />other stuff</txp:if_variable>
or nest like this:
<txp:if_variable name="body_content_article_prev_audit" value="">
Outcome 1
<txp:else />
<txp:if_variable name="body_content_article_prev_audit" value="1">
Outcome 2
<txp:else />
Outcome 3
</txp:if_variable>
</txp:if_variable>
With that in mind, can I check the previous and next articles with article_custom
-esque attributes?
Offline
Re: Boolean check for previous, next and related articles
gaekwad wrote #278928:
I’m using variables, and I would like to keep the content of each variable to a minimum. Perhaps this is a false economy but it makes sense in my brain.
I can create a variable that checks for related articles and sets the variable to
1
if there are related articles:
<txp:variable name="body_content_article_related_audit" value='<txp:related_articles form="audit" limit="1" />' />...
This will spare a db query (to retrieve audit
form):
<txp:variable name="body_content_article_related_audit" value='<txp:related_articles limit="1">1</txp:related_articles>' />
I can check to see if the there is something set in the variable, but I can’t do an exact check against it
You can still check it for emptiness?
Offline
Re: Boolean check for previous, next and related articles
Hi Oleg – thank you for your reply. I will streamline the number of queries and, as you say, check for emptiness after all. That sounds like a much more manageable option.
As always, I am grateful for your time and attention.
Offline