Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-12-06 20:50:37

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Display content based on URL snippet

Having a bad head day – can’t figure out what must be a simple problem.

I have this code in a gallery page, which pulls out a couple of Flickr sets, and displays thumbnails:

<txp:if_section name="gallery">
<txp:vdh_flickr_thumbnails nsid="123@N05" thumbnails_form="flickr_gallery_view" open="lightbox" set="1234" />
<txp:vdh_flickr_thumbnails nsid="123@N05" thumbnails_form="flickr_gallery_view" open="lightbox" set="12345" />
</txp:if_section>

That works fine. What I would like to though is enter URL’s like so in some articles: http://domain.com/gallery/?set=123456

The goal is this:

  1. If accessing the /gallery page, show the two sets as in the code above
  2. If accessing /gallery/?set=123456, display only the set called in the URL, and not the other two sets

Must be easy, but I can’t figure it out today. With the use of txp:variable perhaps? Have not tried the new 4.07 tags much yet..

Offline

#2 2008-12-06 21:06:07

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

Re: Display content based on URL snippet

This was traditionally something for chs_if_urlvar. I think a few others have since surfaced, including smd_if/smd_var and … another one I saw released only recently but that I can’t find now.

Last edited by jakob (2008-12-07 12:06:15)


TXP Builders – finely-crafted code, design and txp

Offline

#3 2008-12-06 22:55:28

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: Display content based on URL snippet

Thanks Julian. I have started to play around with txp:variables for the first time, and came across adi_gps. Seems like we can be in business ;-)

So far, I have this code at the top of the page:

<txp:variable name="from_article" value='<txp:adi_gps />' />

And this further below:

<txp:if_section name="test">
<txp:if_variable name="from_article">
<txp:vdh_flickr nsid="12345@N05" thumbnails_form="flickr_gallery_view" open="lightbox" set="12345" />
</txp:if_variable>
</txp:if_section>

I notice you can’t put an <txp:else /> in the middle of the if_variable conditional? At least, it does not work in my testing.

Question: How to assign the from_article variable to the Flickr set name? Does not work in testing.

Last edited by jstubbs (2008-12-07 01:05:34)

Offline

#4 2008-12-07 00:27:39

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Display content based on URL snippet

jstubbs wrote:

I notice you can’t put an <txp:else /> in the middle of the if_variable conditional? At least, it does not work in my testing.

Yes you can. But with this line: <txp:if_variable name="from_article"> you are checking if the variable exists. Even if the value is empty, the variable still exists. So this condition will always return true. If you want to check if it has a value, you can do this:

<txp:if_variable name="from_article" value="">
   <txp:vdh_flickr nsid="21914846@N05" thumbnails_form="flickr_gallery_view" open="lightbox" set="72157603482231616" />
<txp:else />
   <txp:vdh_flickr nsid="21914846@N05" thumbnails_form="flickr_gallery_view" open="lightbox" set='<txp:variable name="from_article" />' />
</txp:if_variable>

Offline

#5 2008-12-07 01:10:09

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: Display content based on URL snippet

Sigh. Not quite working :-(

<txp:if_section name="test">
<txp:if_variable name="from_article" value="">
<txp:vdh_flickr nsid="123@N05" thumbnails_form="flickr_galleri_view" open="lightbox" set='<txp:variable name="from_article" />' />
<txp:else />
<txp:vdh_flickr_thumbnails nsid="123@N05" thumbnails_form="flickr_galleri_view" open="lightbox" set="12345" />
<txp:vdh_flickr_thumbnails nsid="123@N05" thumbnails_form="flickr_galleri_view" open="lightbox" set="54321" />
</txp:if_variable>
</txp:if_section>

If there is a variable, I get the “failed to connect to Flickr” error. If no variable, I get ALL Flickr sets displaying, rathe than just the two. Very odd!

Offline

#6 2008-12-07 02:34:48

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Display content based on URL snippet

jstubbs wrote:

Sigh. Not quite working :-(

Just shuffle your code around a bit :)

<txp:if_section name="test">
<txp:if_variable name="from_article" value="">
   // the value is empty == URL: /gallery/
<txp:vdh_flickr_thumbnails nsid="123@N05" thumbnails_form="flickr_galleri_view" open="lightbox" set="12345" />
<txp:vdh_flickr_thumbnails nsid="123@N05" thumbnails_form="flickr_galleri_view" open="lightbox" set="54321" />
<txp:else />
   // the value is not empty == URL: /gallery/?set=something
<txp:vdh_flickr nsid="123@N05" thumbnails_form="flickr_galleri_view" open="lightbox" set='<txp:variable name="from_article" />' />
</txp:if_variable>
</txp:if_section>

Offline

#7 2008-12-07 08:38:45

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: Display content based on URL snippet

Half way there! Your code shuffling almost works…but not quite.

If I visit /test, I get “the value is empty == URL: /test/” and the two sets display correctly.

If I visit /test/?set=12345—-, I get the same output – “the value is empty == URL: /test/” and the two sets….

The variable is set at the top of the page like so:
<txp:variable name="from_article" value='<txp:adi_gps />' />.

Reckon its going wrong there?

Offline

#8 2008-12-07 09:00:47

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: Display content based on URL snippet

I fixed it! Here is what I have now:

Top of page, I changed the variable name to set, which reflects the actual variable name:

<txp:variable name="set" value='<txp:adi_gps />' />

Then, to source the sets according to the URL:

<txp:if_section name="test">
<txp:adi_gps name="set" list="1" />
<txp:if_variable name="set" value="">
the value is empty == URL: /test/
<txp:vdh_flickr_thumbnails nsid="123@N05" thumbnails_form="flickr_galleri_view" open="lightbox" set="1234" />
<txp:vdh_flickr_thumbnails nsid="123@N05" thumbnails_form="flickr_galleri_view" open="lightbox" set="12345" />
<txp:else />
the value is not empty == URL: /test/?set=something
<txp:vdh_flickr nsid="123@N05" thumbnails_form="flickr_galleri_view" open="lightbox" set='<txp:variable name="set" />' />
</txp:if_variable>
</txp:if_section>

For anyone else reading, the key part was discovering that adi_gps has a list attribute for debugging: <txp:adi_gps name="set" list="1" />. Awesome! Thanks Els!!

Offline

#9 2008-12-07 12:09:09

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

Re: Display content based on URL snippet

… and another one I saw released only recently but that I can’t find now

… and came across adi_gps.

That’s it! Nice write-up on txp tips too.


TXP Builders – finely-crafted code, design and txp

Offline

#10 2008-12-07 14:41:51

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Display content based on URL snippet

Ah, now I get it! I thought that <txp:adi_gps /> displayed just the GET variable, but I overlooked that it created the txp variable as well:

<txp:adi_gps name="myvar1" />

- extract a variable called myvar1 from URL, create a TXP variable of the same name and display it’s value.

…which means that this:

<txp:variable name="set" value='<txp:adi_gps />' />

is superfluous and won’t work at all of course. If you still have that on your page, you can remove it.

EDIT: Jonathan, you might want to update your TXP Tip ;)

Last edited by els (2008-12-07 14:54:21)

Offline

#11 2008-12-07 15:12:52

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: Display content based on URL snippet

Sigh! I still don’t totally get this variable stuff, but I guess that’s ok since its my first day playing with it :-)

Can you check the TXP Tip again for veracity?

Offline

#12 2008-12-07 15:48:29

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Display content based on URL snippet

It looks very clear to me. I assume you verified that it was OK to remove the first variable tag? ;)

You haven’t chosen the simplest example of the use of the variable tag to begin with, for because of the adi_gps plugin you don’t actually see the variable being set (in the code). But you’ve made it clear in your text that the plugin does that.

I like the way TXP Tips is growing!

Offline

Board footer

Powered by FluxBB