Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-04-22 23:18:04

raminrahimi
Member
From: India
Registered: 2013-03-19
Posts: 276

show something if i'm in a specific URL

i want to display something if page-url is in a specific address.
example have a section of price ==> if i’m in <txp:page_url />price then want to show <h1>Price Page</h1>
i tried like this, but not works :-(

<txp:variable name="pfr" value='<txp:page_url type="pfr" />' />
<txp:if_variable name="pfr" value='<txp:site_url />english'>
<h1>Price Page</h1>
</txp:if_variable>

Last edited by raminrahimi (2015-04-22 23:18:36)

Offline

#2 2015-04-23 00:40:43

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

Re: show something if i'm in a specific URL

if_article_id ?

Or maybe somehow

page_url

Offline

#3 2015-04-23 06:23:35

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,596
Website

Re: show something if i'm in a specific URL

In your example, it looks as if you’re reinventing the wheel: the standard way to render a specific title for a section is to use <txp:section title="1" /> and a specific title for an article to use <txp:title />. So in your template you could do:

<h1><txp:section title="1" /> Page</h1>

or if you just need page to appear after the section name in this one case:

<txp:if_section name="price">
  <h1><txp:section title="1" /> Page</h1>
<txp:else />
  <h1><txp:section title="1" /></h1>
</txp:if_section>

An ever shorter way of doing the same is <h1><txp:section title="1" /><txp:if_section name="price"> Page</txp:if_section></h1> but the code is not so readable.

tye’s suggestion of using if_article_id is good if you have a specific message that needs to be associated with a particular page. But as soon as you need to do this for several pages, it becomes hard to maintain and you need a lot of if-statements to achieve it. My suggestion would then be to place that page-specific content with the article itself: either in the ‘body’ or ‘excerpt’ fields, or if those are already in use or not suitable, to create a custom field to hold that information.


TXP Builders – finely-crafted code, design and txp

Offline

#4 2015-04-23 06:38:49

raminrahimi
Member
From: India
Registered: 2013-03-19
Posts: 276

Re: show something if i'm in a specific URL

i tried with different options, but didn’t success :-(

this will show to all articles, category, search of the section of price:
<txp:if_section name="price">
<h1><txp:section title="1" /> Page</h1>
<txp:else />
<h1><txp:section title="1" /></h1>
</txp:if_section>

but i need to show <h1><txp:section title="1" /> Page</h1> just on the root of that section (http://localhost/price) not on all any other pages of that section.

Last edited by raminrahimi (2015-04-23 06:48:12)

Offline

#5 2015-04-23 07:10:19

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

Re: show something if i'm in a specific URL

This is based on Oleg’s solution

<txp:if_section name="price">
<txp:variable name="pricepage" value='<txp:page_url type="q" />-<txp:page_url type="c" />-<txp:page_url type="author" />-<txp:page_url type="pg" />-<txp:page_url type="s" />' />
<txp:if_variable name="pricepage" value="----price">
 <h1><txp:section title="1" /> Page</h1>
<txp:else />
<h1><txp:section title="1" /></h1>
</txp:if_variable>
</txp:if_section>

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

Offline

#6 2015-04-23 09:50:30

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,596
Website

Re: show something if i'm in a specific URL

Wow Yiannis, that’s a pretty extensive check and would certainly work.

Nevertheless, I’d still advocate the simpler route of using txp’s in-built tags if_article_list tag – and the if_category tag if the page template is also doing category filtering – as that is what they were designed for.

The thread you linked to is especially about the home page (default section), which is also the standard url destination for author, search and category filtering, so all those cases need handling. For most section templates, that won’t apply (with the exception perhaps of category filtering).

So this:

<txp:if_article_list>
  <txp:if_section name="price">
    <h1><txp:section title="1" /> Page</h1>
  <txp:else />
    <h1><txp:section title="1" /></h1>
  </txp:if_section>
</txp:if_article_list>

You could also us the normal listform and form attributes in txp:article to do the article_list / individual_article filtering and then in your listform use if_first_article to insert the heading…

<txp:article listform="price_list" form="price_item" />

and in the price_list form:

<txp:if_first_article>
  <h1><txp:section title="1" /> Page</h1>
</txp:if_first_article>
<!-- rest of price list output -->

The assumption here is that the price_list form will only ever appear on the price page, so you don’t need to do the if_section bit, as it won’t be used anywhere else. The same goes for the page template too: if you’re using that page template only for the price section, there’s no need to test for if_section section=“price”, because the page template isn’t used anywhere else.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB