Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-09-13 15:10:18

gaekwad
Multi-hyphenate
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 3,531
GitHub

[howto] Determining the state of Textpattern-rendered output

When I’m building a site, it’s useful to me to be able to see what state a URL has according to Textpattern. At this stage, I need to work out if a page is any of the following:

  • the front page
  • an article list
  • an individual article
  • search results
  • a missing page (HTTP 404 error)

This is how I’m doing it right now:

<txp:if_status status="404">
<p>is 404</p>
<txp:else />
<p>is not 404</p>
<txp:if_search>
<p>is search results</p>
<txp:else />
<p>is not search results</p>
<txp:if_individual_article>
<p>is individual article</p>
<txp:else />
<p>is not individual article</p>
<txp:if_article_list>
<p>is article list</p>
<txp:if_section name=",default">
<p>is front page</p>
<txp:else />
<p>is not front page</p>
</txp:if_section>
<txp:else />
<p>is not article list</p>
</txp:if_article_list>
</txp:if_individual_article>
</txp:if_search>
</txp:if_status>

This works — it does the job I need it to do. It’s basic and ugly. I’ll likely add to it when I get further along with the build, but I wanted to share what I have so far.

Last edited by gaekwad (2012-09-13 15:12:36)

Offline

#2 2012-09-13 16:17:13

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,616
Website GitHub Twitter

Re: [howto] Determining the state of Textpattern-rendered output

Hi Pete,

you can make it slightly more context responsive by using

<txp:if_search>
<!-- search results -->
<txp:else />
<txp:if_article_list>
<!-- article list page, either section or category -->
<txp:variable name="categoryname" value='<txp:page_url type="c" />' />
<!-- detect if you are in a category page -->
<txp:if_variable name="categoryname" value="">
<txp:if_section name="">
<!-- home page -->
<txp:else />
<!-- section home page -->
</txp:if_section>
<txp:else />
<!-- category page -->
</txp:if_variable>
<txp:else />
<!-- individual article page -->
</txp:if_article_list>
</txp:if_search>

The error pages can be handled by the error page so they don’t have to be included in this tree


Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.

Offline

#3 2012-09-13 16:34:00

gaekwad
Multi-hyphenate
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 3,531
GitHub

Re: [howto] Determining the state of Textpattern-rendered output

Hi Yiannis — thanks, you’ve just saved me posting the next iteration I was working on! :)

Offline

#4 2012-09-13 16:58:40

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,616
Website GitHub Twitter

Re: [howto] Determining the state of Textpattern-rendered output

All we need to do now is think how <txp:variable name="authorname" value='<txp:page_url type="author" />' /> can be included in there:)


Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.

Offline

#5 2012-09-13 17:18:11

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,616
Website GitHub Twitter

Re: [howto] Determining the state of Textpattern-rendered output

Maybe something like this… Untested.

<txp:if_search>
<!-- search results -->
<txp:else />
<txp:if_article_list>
<!-- article list page, either section or category -->
<txp:variable name="authorname" value='<txp:page_url type="author" />' />
<txp:if_variable name="authorname" value='<txp:page_url type="author" />'>
<!-- author article list -->
<txp:else />
<txp:variable name="categoryname" value='<txp:page_url type="c" />' />
<!-- detect if you are in a category page -->
<txp:if_variable name="categoryname" value="">
<txp:if_section name="">
<!-- home page -->
<txp:else />
<!-- section home page -->
</txp:if_section>
<txp:else />
<!-- category page -->
</txp:if_variable> <!-- end category variable -->
</txp:if_variable> <!-- end author variable -->
<txp:else />
<!-- individual article page -->
</txp:if_article_list>
</txp:if_search>

Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB