Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[solved] Troubleshooting variables: previous and next articles
When viewing an individual article, I’d like to output a link to the next article if one exists, along with an h6
header. To do this, I’m creating a variable and setting it to the next post title using next_title
. I then query the variable and, if it has a value (i.e., the next post title), output the markup. If there is no next article, I expect to have a variable with a name but no value, and nothing should happen. I am doing the same with the previous articles, but with prev_title
and a different variable name.
When I view my first article, there is no previous article, and when I view my last article there is no next article. This is what I expect but, somewhat confusingly, it isn’t happening.
Here’s my code for the ‘next’ link:
<txp:variable name="body_content_article_next" value="<txp:next_title />" />
<txp:if_variable name="body_content_article_next" value="">
<txp:else />
<h6>Next up in <txp:section title="1" /></h6>
<ul>
<li><txp:link_to_next><txp:next_title /></txp:link_to_next></li>
</ul>
</txp:if_variable>
And here’s the tag trace from the source of when the last article is viewed:
<txp:variable name="body_content_article_next" value="<txp:next_title />" />
<txp:if_variable name="body_content_article_next" value="">
[<txp:if_variable name="body_content_article_next" value="">: false]
<txp:section title="1" />
<txp:link_to_next>
</txp:link_to_next>
</txp:if_variable>
If I debug some more and output my variable into the markup as a comment (see line #2):
<txp:variable name="body_content_article_next" value="<txp:next_title />" />
<!-- <txp:variable name="body_content_article_next" /> -->
<txp:if_variable name="body_content_article_next" value="">
<txp:else />
<h6>Next up in <txp:section title="1" /></h6>
<ul>
<li><txp:link_to_next><txp:next_title /></txp:link_to_next></li>
</ul>
</txp:if_variable>
…I get an empty comment:
<!-- -->
I get the same thing with the ‘previous’ code block when I’m viewing the first article: the h6
, ul
and li
are all parsed as if the variable has a value, but the link to the previous article isn’t shown because it doesn’t exist.
Any suggestions or advice is most graciously received. Thank you in advance.
Last edited by gaekwad (2014-02-14 15:12:09)
Offline
Re: [solved] Troubleshooting variables: previous and next articles
It should be
<txp:variable name="body_content_article_next" value='<txp:next_title />' />
note the single quotes
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: [solved] Troubleshooting variables: previous and next articles
Guh – of course. Good spot; thank you so much, Yiannis.
Offline