Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-06-27 14:07:28

leafy_loader
Member
Registered: 2008-09-25
Posts: 96

How to test if article id is present in URL

I am trying to set up a conditional test for wether the artcle id is present in the URL. Thought it would be a simple task but proving not to be the case. Here’s my code

<txp:output_form form=“id_test” />

following is in the form “id_test” ;

——————————————————

<txp:article> <txp:if_article_id> <txp:variable name=‘currId’ value=’<txp:article_id />’ /> <txp:else /> <txp:variable name=‘currId’ value=’‘ /> </txp:if_article_id>
</txp:article>
<txp:article_custom category=’<txp:category />’ sort=“position asc”> <txp:if_variable name=‘currId’ value=”“> title=“no id” <txp:else /> title=“id exists” </txp:if_variable>
</txp:article_custom>

It works if the id is present but doesn’t if there is no id.

What am I missing here?

Last edited by leafy_loader (2011-06-27 14:31:02)

Offline

#2 2011-06-27 14:34:29

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

Re: How to test if article id is present in URL

I’m not quite sure what you are trying to achieve. Can you describe the situation you need this for?

AFAIK txp:if_article_id can only be used to test if the current article matches a particular id (e.g. “is the article currently showing number 3?”) so it cannot work the way you have used it. Aside from that, every article has an id even if you don’t see it show in the URL.

Only non-individual-article pages do not have an id but they are not articles and so won’t show in your article_custom tag either. If you are trying to determine whether you are viewing an individual article or an article list, you can do that with txp:if_individual_article.

If you want to retrieve the current URL that shows on a page you can use txp:page_url with the attribute type="request_uri". Otherwise, the other way to retrieve the link to an article is to use txp:permlink.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2011-06-27 14:55:00

leafy_loader
Member
Registered: 2008-09-25
Posts: 96

Re: How to test if article id is present in URL

I need to test wether the id=354 is present in the url so I can branch the code. I’m going to use raw php to test for the $_GET[‘id’] variable if it’s not possible using textpattern tags.

Thanks

Offline

#4 2011-06-27 15:33:30

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

Re: How to test if article id is present in URL

If you want to test if the current article is id=354 you can do:

<txp:if_individual_article>
   <txp:if_article_id id="354">show me some special content</txp:if_article_id>
</txp:if_individual_article>

Otherwise you can use adi_gps or rah_if_gps to retrieve the id value passed via the url (post or get) and respond accordingly. With rah_if_gps the if-construction is built-in, with adi_gps it creates a variable out of the get/post var and you use txp:if_variable to test against it.

Note that as far as I understand it at least, the article id is always passed as an url variable even if you don’t see it due to url rewriting. You may need to experiment with the above plugins (get/post settings). If you can’t get that to work, you can use txp:page_url to extract the url as described in the post above and then use php (or rah_function as bridge to php) to see if your desired string is in the url string somewhere.

Last edited by jakob (2011-06-27 15:34:39)


TXP Builders – finely-crafted code, design and txp

Offline

#5 2011-06-27 15:46:54

leafy_loader
Member
Registered: 2008-09-25
Posts: 96

Re: How to test if article id is present in URL

354 was just a number I used as an example. I want to test for the presence of the id variable. I will do this with raw php, nearly there

Offline

Board footer

Powered by FluxBB