Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-02-13 12:28:02

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

How to get more txp:else options than just two?

I’m in need of creating a channel that outputs the articles of multiple contributing authors. So far so good.

Next I need to show a headshot of each author in their respective articles. I want to set this up so they don’t even have to think about adding the images themselves (because they probably won’t or will get it wrong), rather they are simply recognized by their login and the image is added automagically if they publish the article in the right section. I can do this easy enough for two authors by using this in the list form:

<txp:if_article_author name="author1">
   <txp:image id="2" class="author-thumb" />
   <p class="author-info">by</p>
   <p class="author-info"><txp:author /><br />Author1's Function</p>
   <p class="author-info"><txp:posted /></p>
<txp:else />
   <txp:if_article_author name="author2">
     <txp:image id="16" class="author-thumb" />
     <p class="author-info">by</p>
     <p class="author-info"><txp:author /><br />Author2's Function</p>
     <p class="author-info"><txp:posted /></p>
   </txp:if_article_author>
</txp:if_article_author>

However, I need to have the context work for any number of authors beyond just 2. Apparently adding another else and repeating new if article author blocks does not work. :(

Is there a way to set up the condition so I can define new authors beyond two as they are realized?

This is a huge one if you can help.

Last edited by Destry (2009-02-13 12:33:02)

Offline

#2 2009-02-13 12:42:07

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,453
Website GitHub

Re: How to get more txp:else options than just two?

Well, you could do some nesting but it’s going to get hairy a few layers in. You actually don’t need the else at all, since each article can only be authored by one person, this will suffice:

<txp:if_article_author name="author1">
  <txp:image id="2" class="author-thumb" />
  <p class="author-info">by</p>
  <p class="author-info"><txp:author /><br />Author1's Function</p>
  <p class="author-info"><txp:posted /></p>
</txp:if_article_author>

<txp:if_article_author name="author2">
  <txp:image id="16" class="author-thumb" />
  <p class="author-info">by</p>
  <p class="author-info"><txp:author /><br />Author2's Function</p>
  <p class="author-info"><txp:posted /></p>
</txp:if_article_author>

...

The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2009-02-13 12:43:02

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: How to get more txp:else options than just two?

I should point out, in case it’s not obvious, that besides not wanting to make authors add, say, even a single image ID number in the article_image field (which would be the next best approach: Plan B), I need for there to be the author’s “job function” information under their name (note in code above). To do this using plan B, I would likely need to use a custom field too, and then I’ve just increased the author’s need to add both an image ID and custom field data. That’s getting further from the original goal of not making them add anything.

Ed.: Ah your fast, Blokey!

Last edited by Destry (2009-02-13 12:44:32)

Offline

#4 2009-02-13 12:45:08

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: How to get more txp:else options than just two?

Sweet. So it’s as easy as dropping the else? /* slaps head */

Ed.: Er…uh…and adding the missing conditional wrap piece thingy. Never mind, I’ll just copy the code :)

Last edited by Destry (2009-02-13 12:47:38)

Offline

#5 2009-02-13 12:51:42

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,453
Website GitHub

Re: How to get more txp:else options than just two?

Destry wrote:

Sweet. So it’s as easy as dropping the else?

In theory yeah. Shouldn’t slow things down too much even though it’s got to check each author instead of — as a series of nested else statements — only going as far is it needs then dropping out.

Incidentally, if you do put your job function info in a custom field you can make a nice form out of most of the content and save some typing:

<txp:if_article_author name="author1">
  <txp:image id="2" class="author-thumb" />
  <txp:output_form form="bio" />
</txp:if_article_author>

bio:

<p class="author-info">by</p>
<p class="author-info"><txp:author /><br /><txp:custom_field name="job_function" /></p>
<p class="author-info"><txp:posted /></p>

Yay! But I’m sure you figured that out already.

EDIT: I did actually have plans to offer another plugin in my “programmers’ / geeks’ repertoire” for a “switch” statement for this exact scenario. e.g:

<txp:smd_switch item='<txp:author />'>
<txp:smd_case match="author1">
  // Do some author 1 goodness
</txp:smd_case>
<txp:smd_case match="author2">
  // Do some author 2 goodness
</txp:smd_case>
...
<txp:smd_default>
  // Do some generic goodness if none of the above matched
</txp:smd_case>
</txp:smd_switch>

Pretty easy to do, and it would offer fallthrough/break as well (programmers will know what I mean here).

One day, maybe…

Last edited by Bloke (2009-02-13 12:59:01)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#6 2009-02-13 12:58:41

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: How to get more txp:else options than just two?

Good call about the bio form!

In theory, I can’t imagine more than, say, 10 authors over time, and that’s probably a stretch; five would be a certainty, maybe 8-ish. How much speed impact are we guestimating here?

Ed.: I’d be interested in such a plugin for situation like this. It would be a great resource for multiple author sites; especially if it meant not impacting speed in comparison.

Last edited by Destry (2009-02-13 13:01:52)

Offline

#7 2009-02-13 13:01:01

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,453
Website GitHub

Re: How to get more txp:else options than just two?

Destry wrote:

How much speed impact are we guestimating here?

If it’s only for a handful of users like that, the act of checking ten conditional statements is probably less than the “weight” of the parser having to keep track of 9 nested else calls on the stack :-)

No disrespect to the parser— for it is mighty — but it’s gotta keep track of it all somehow and the nested elses definitely add memory overhead, if not time as well.

EDIT: The plugin’s definitely on the Todo list.

Last edited by Bloke (2009-02-13 13:03:13)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#8 2009-02-13 15:30:06

merz1
Member
From: Hamburg
Registered: 2006-05-04
Posts: 994
Website

Re: How to get more txp:else options than just two?

Well, nice but only a workaround.

  1. To me the request looks like the request for a new core ‘role model’ TXP article tag like <txp:article_author_info form="bio_long" /> or maybe a plug-in?
  2. An alternative would be to have an address book with many many fields and from those fields the article_author_info could be pulled & posted.

The request is of course based on the fact ’1 article = 1 author’ which might become a limitation by itself in our collaborative world :).

Btw: When starting with TXP I seriously missed an address book and an event calendar. Any ideas on that?


Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML

Offline

#9 2009-02-13 15:37:01

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: How to get more txp:else options than just two?

Interesting ideas, Markus.

I’ve heard good things about Bloke’s new Calendar plugin which you can find here, and probably elsewhere.

Offline

#10 2009-02-13 15:38:03

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,453
Website GitHub

Re: How to get more txp:else options than just two?

merz1 wrote:

Well, nice but only a workaround.

True in this case. But a general-purpose switch/case is actually quite handy in a few other places too.

<txp:article_author_info form="bio_long" /> or maybe a plug-in? An alternative would be to have an address book

Would make sense as a plugin. Didn’t someone make one already? Thought I’d seen one somewhere (or at least a partial implementation). Maybe I’ve been dreaming again.

Could always use txp:variables to hold data and build up a bio on each person in a form that’s included on every page. But that’s another workaround, I guess!

I seriously missed an address book and an event calendar. Any ideas on that?

Yes to the event calendar bit ;-)

EDIT: Destry beat me to it :-)

Last edited by Bloke (2009-02-13 15:38:54)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#11 2009-02-13 21:01:11

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: How to get more txp:else options than just two?

Off the top of my head, you could automate the user photo part too by using an appropriate image name:

For instance, say my username was “mary”. I would upload an image named “mary.jpg” and then in my form:

<txp:image name="<txp:php>echo $thisarticle['authorid'];</txp:php>" class="author-thumb" />

Offline

#12 2009-02-13 21:26:37

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: How to get more txp:else options than just two?

Wow, that’s slick too, Mary. Thanks.

I see how this could work well in my project. In fact it’s a site for an association that has a board structure (president, vice president, secretary, etc.). These people serve terms in these roles, until replaced (or re-elected) at election time.

So, as an alternative to names, the usernames could be their roles (which is how it currently is). New elected members then just adopt the user accounts when it’s time (changing passwords) and re-upload images on the previous versions.

A very worthy alternative that fits a recognizable structure.

Offline

Board footer

Powered by FluxBB