Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[howto] Creating a lab section to manage classic "example.html" pages
Note: this is a proof of concept. I haven’t tested the idea, so it may need some tuning.
Creating a lab section to manage classic “example.html” pages
The idea.
To have a section where you can create “example pages” for that kind of articles that needs one or more examples pages.
By “example pages” I mean pages like, for example, the ones that are listed in 456bereastreet lab.
Usually, this kind of standalone “example” pages needs their custom <html>
, <head>
, <body>
, including custom CSS/JS.
The minimalistic approach:
1. Create a “Lab” section (or “Examples”, or whatever)
2. Create a “Lab” page.
3. Then, in the “Lab” page template, put just this:
<txp:if_individual_article><txp:body /></txp:if_individual_article>
(*)
4. Go to the Write tab, write a title, and in the article body, write/paste all your “example page” code, including the <html>
, <head>
and <body>
.
(You may need to disable/escape Textile).
5. Publish it to the “Lab” section.
That’s all, if everything works as I think it should, you go to the article permlink and you should see your “example” page.
Some benefits:- the example page is searchable using the internal TxP site seach
- you don’t have to upload it via FTP
(*) if that doesn’t work, you can try this:
<txp:if_individual_article><txp:article form="body" /></txp:if_individual_article>
And then create a body form with just <txp:body />
inside.
Expanding the idea
- Excerpt field: you can use it to write a description of the “example” page and then have an “example” list page like this one: 456bereastreet lab
You will need to add some more tags to the “Lab” page, something like this:
<txp:if_individual_article><txp:body /><txp:else /><txp:article form="my-example-excerpt" /></txp:if_individual_article>
- Custom fields: can be used in many ways. For example, as triggers. Imagine you have a <head>
or maybe some <style></style>
that you use in more than one example.
So, you create a form and paste that code you use more than once.
In your article body you write/paste your code but without including, for example the head.
Then, you use some conditional custom field magic in your page template:
<txp:if_individual_article><txp:if_custom_field name="customHead"><txp:output_form name="myCustomHead"><txp:body /><txp:else /><txp:body /></txp:if_custom_field></txp:if_individual_article>
You may need to think hard about where to open/close <html>
, <head>
and <body>
tags.
An “alternative” approach
Following the idea of using custom fields as triggers, you can use the article body field just to paste the “relevant” code (usually, the code inside <body>
), and then use the custom fields to trigger some conditionals and so, include any form (with custom CSS, JS, <head>
, etc).
In that case, the “Lab” page template can be something like this:
<!DOCTYPE html etc etc etc>
<html>
... some conditional tricks to include different <head>s
<body>
<txp:body />
</body>
</html>
——————-
Well, that’s all by now. I hope this makes sense and, if someone tests it and works, please, give feedback.
The true is: I don’t know if you can easily include <html>
, <head>
and <body>
tags in a Txp article body.
Last edited by maniqui (2008-05-24 05:09:01)
Offline
#2 2007-06-06 07:28:58
- FireFusion
- Member
- Registered: 2005-05-10
- Posts: 698
Re: [howto] Creating a lab section to manage classic "example.html" pages
Good tutorial. Very useful.
Offline
#3 2007-06-06 10:09:07
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: [howto] Creating a lab section to manage classic "example.html" pages
(You may need to disable/escape Textile).
You definitely should turn off Textile altogether.
Why didn’t you post this on the WIKI?
Offline
Re: [howto] Creating a lab section to manage classic "example.html" pages
Some correction:
maniqui wrote:
In that case, the “Lab” page template can be something like this:
<!DOCTYPE html etc etc etc>
<html>
... some conditional tricks to include different <head>s
<body>
<txp:body />
</body>
</html>
That should be something like this:
<txp:if_individual_article><!DOCTYPE html etc etc etc>
<html>
... some conditional tricks to include different <head>s
<body>
<txp:body />
</body>
</html>
</txp:if_individual_article>
I think you will need to be careful with possible white spaces or blank lines before the doctype. I think the may lead to problems so try to avoid them.
Mary wrote:
Why didn’t you post this on the WIKI?
I don’t know!
I know I have a WIKI account and I have use it few times sometime ago.
I’m not sure if I could have written this in a WIKI syntax.
But maybe I can find a time to move the tutorial there and learn something new.
Offline