Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-10-20 19:22:10

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

How do I publish an article in multiple formats simultaneously?

Hi!

I’m working on a new site for an academic journal, and I need to dynamically generate article information in several formats for each article:

  1. The main article page will include the title, body, publication dates and various custom fields.
  2. Another page will include the title, excerpt, keywords, and other custom fields,
  3. Another page will be in plain text and display mostly custom field info.

How can I get Textpattern to generate the same article in these different formats available at different URLs? I imagine there is an easy way to do this, but I can’t think of it right now.

Thanks!

Offline

#2 2009-10-20 19:28:41

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

Re: How do I publish an article in multiple formats simultaneously?

It would be fairly simple using chs_if_urlvar, but it’s an old plugin and I assume there are newer ones that can do it as well or even better.

Offline

#3 2009-10-20 19:45:44

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: How do I publish an article in multiple formats simultaneously?

So you’re saying you would have URLs kind of like this:

/articles/articleA
 -> your #1
/articles/articleA/?view=nobody (or something)
 -> your #2
/articles/articleA/?view=plain
 -> your #3

Is that what you’re looking for? If so, you could use some PHP:

<txp:php> 
// untested. you could also use a switch statement, but this should work.
// view => form name
$views = array('nobody'  => 'nobody',
               'plain'   => 'plain');
// which form to use
$form = empty(gps('view')) ? 'defaultform ' :
                              $views[htmlspecialchars(gps('view'))];
echo article(array('form' => $form));
</txp:php>

Last edited by jm (2009-10-20 19:46:06)

Offline

#4 2009-10-20 19:57:55

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

Re: How do I publish an article in multiple formats simultaneously?

Yes, jm’s approach is the way I’d go. As an alternative along the same theme, here’s a non-PHP mechanism that jakob used on a project recently that I thought was so good I’m going to steal it ;-)

<txp:adi_gps name="view" quiet="1" />
<txp:variable name="action" value="normal" />
<txp:if_variable name="view" value="condensed"><txp:variable name="action" value="condensed" /></txp:if_variable>
<txp:if_variable name="view" value="plain"><txp:variable name="action" value="plain" /></txp:if_variable>

So your URLs are site.com/section/article, possibly with ?view=plain or ?view=condensed after it. Then further on you can use the variables like this:

<txp:output_form form='display_<txp:variable name="action" />' />

or better, as jm suggests:

<txp:article form='display_<txp:variable name="action" />' />

Then just make up your three forms display_normal, display_plain and display_condensed to control how it all looks and you’re awaaaaay.

Last edited by Bloke (2009-10-20 20:00:56)


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

#5 2009-10-21 13:58:26

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: How do I publish an article in multiple formats simultaneously?

Thanks, folks! You guys are awesome. I shall experiment with these methods today!

Offline

#6 2009-10-21 19:20:28

masa
Member
From: Asturias, Spain
Registered: 2005-11-25
Posts: 1,091

Re: How do I publish an article in multiple formats simultaneously?

The post title caught my attention, and since I don’t know much about PHP, I was wondering, whether one couldn’t achieve similar results by using additional sections?

Publish the articles to the main section and then use article_custom in the other sections to alter the presentation.

?

Sure, the URL would look different, but what the heck.

Offline

#7 2009-10-21 19:24:52

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: How do I publish an article in multiple formats simultaneously?

@masa: I thought of that, but I need to have the different views in individual article context. I can see using article_custom to output the articles in a different section in aggregate but not as discrete units. Do you see a way around that?

Offline

#8 2009-10-21 19:44:06

masa
Member
From: Asturias, Spain
Registered: 2005-11-25
Posts: 1,091

Re: How do I publish an article in multiple formats simultaneously?

johnstephens wrote:

I thought of that, but I need to have the different views in individual article context.

I admit, this is a bit more complicated than what I’ve done :) , but from your description, it sounds like the perfect application for a style switcher:

output the entire article in its full glory and then use a switcher to toggle bits and/or reformat them in situ.

Offline

Board footer

Powered by FluxBB