Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 Yesterday 18:31:38

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,909
GitHub

Overriding page template from URL query

Is it possible to override the defined page template for a given section with a URL query? If so, what’s the cleanest / sanest route?

For example, I have a section calendar with a HTML page, and I’m using /section/title URL by default. The page uses article_custom to draw from multiple categories. The messy URL looks like this:

https://example.com/?s=calendar

This link as-is will render HTML in a browser. Ideally, I’d like to have 1 or more non-HTML formats (including e.g. iCalendar) that uses the same section name (calendar), and the page template is specified from the URL. The messy URL might look like this:

https://example.com/?s=calendar&page=icalendar

It feels like I’m missing something obvious, and my docs search-fu has come up short. Lots of long days at the moment, and my brainmeat is not as well-rested as it should be.

Any guidance is warmly welcomed. Thank you.

Offline

#2 Yesterday 18:48:40

etc
Developer
Registered: 2010-11-11
Posts: 5,731
Website GitHub

Re: Overriding page template from URL query

Custom forms, Sir:

https://example.com/?s=calendar&f=icalendar

Pages are historically tied to sections for privacy reasons, but custom forms are freely selectable via URL, caveat utilitor. So just put the code of icalendar page into icalendar custom form, and you should be set, unless my memory fools me.

Offline

#3 Yesterday 19:23:08

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,909
GitHub

Re: Overriding page template from URL query

etc wrote #343537:

Custom forms, Sir:

https://example.com/?s=calendar&f=icalendar...

Pages are historically tied to sections for privacy reasons, but custom forms are freely selectable via URL, caveat utilitor. So just put the code of icalendar page into icalendar custom form, and you should be set, unless my memory fools me.

Thanks very much, etc. This is a departure to my usual route, so please forgive me if I’m misunderstanding it…if the HTML page is essentially hard-coded (tied) to the section, it will still be parsed for the iCalendar ‘container’ before the iCalendar-friendly article form is used for each event…is that correct?

As the (hypothetical) iCalendar page has a fully non-HTML scaffold, I’m interpreting this to mean that I realistically need a separate section with its own page + forms stack. I can accomplish this, it should be easy enough to do, it needs some re-architecting of the site but it’s doable.

Example iCalendar markup follows, for any curious parties:

BEGIN:VCALENDAR
 PRODID:-//xyz Corp//NONSGML PDA Calendar Version 1.0//EN
 VERSION:2.0
 BEGIN:VEVENT
 DTSTAMP:19960704T120000Z
 UID:uid1@example.com
 ORGANIZER:mailto:jsmith@example.com
 DTSTART:19960918T143000Z
 DTEND:19960920T220000Z
 STATUS:CONFIRMED
 CATEGORIES:CONFERENCE
 SUMMARY:Networld+Interop Conference
 DESCRIPTION:Networld+Interop Conference
   and Exhibit\nAtlanta World Congress Center\n
  Atlanta\, Georgia
 END:VEVENT
 END:VCALENDAR

Last edited by gaekwad (Yesterday 19:32:17)

Offline

#4 Yesterday 20:16:53

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

Re: Overriding page template from URL query

If you switch on the “Advanced options” under Admin › Preferences › Admin, you can define a custom form type and give it a corresponding mime-type for downloading the ics file. Something like:

[ics]
mediatype="text/calendar"
title="iCal"

Then create a form with your vcalendar form data and that should trigger an ics download. You can use txp:header to add additional headers if needed.

Then you call it with ?f=formname plus additional url attributes if needed.

There’s an old tutorial on textpattern.tips that shows the principle but uses an old plugin to output the custom form.


TXP Builders – finely-crafted code, design and txp

Offline

#5 Today 07:50:14

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,909
GitHub

Re: Overriding page template from URL query

jakob wrote #343539:

If you switch on the “Advanced options” under Admin › Preferences › Admin, you can define a custom form type and give it a corresponding mime-type for downloading the ics file.

Thanks, jakob – I’ll try that!

Offline

#6 Today 08:58:31

etc
Developer
Registered: 2010-11-11
Posts: 5,731
Website GitHub

Re: Overriding page template from URL query

gaekwad wrote #343538:

if the HTML page is essentially hard-coded (tied) to the section, it will still be parsed for the iCalendar ‘container’ before the iCalendar-friendly article form is used for each event…is that correct?

As the (hypothetical) iCalendar page has a fully non-HTML scaffold, I’m interpreting this to mean that I realistically need a separate section with its own page + forms stack.

No. Custom forms actually act as free pages, overriding this tied to the section. If you create, as Julian suggests, a text/calendar type custom form (call it icalendar, say)

BEGIN:VCALENDAR
 PRODID:-//xyz Corp//NONSGML PDA Calendar Version 1.0//EN
 VERSION:2.0
<txp:article>
 BEGIN:VEVENT
 DTSTAMP:<txp:posted format="..." />
...
 END:VEVENT
</txp:article>
 END:VCALENDAR

you should be able to use it as page substitute for any section:

https://example.com/?s=calendar&f=icalendar or https://example.com/?s=events&f=icalendar

The only restriction is that icalendar must belong to the same theme that the concerned sections.

Offline

Board footer

Powered by FluxBB