Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-08-12 06:19:10

kkobashi
Member
Registered: 2008-01-27
Posts: 51
Website

How to identify all major page types in the default page template?

Has anyone done this excercise of attempting to identify all page types in the default page? I would think that there is a generic structured page template and this should be totally doable.

Assume all sections point to the default page template, the layout is a two column with header, footer, and content container.

From what I understand there are these types of pages:
  • Home page
  • Section page
  • Category page
  • Author page
  • Individual article page
  • Search page
  • Search result page

(if there are more page types, then please list them)

I know about glx_if and asy_wondertag is useful also too by passing appropriate tag results in attributes.

Every page type should be mutually exclusive and accurately identified. If you have to use glx_if and asy_wondertag in your solution, then please do so. I have been playing for the past day trying to do this and frankly, I’m stumped.

Its important for me to get this down because things like page title, meta description, meta keywords, pointing at the right stylesheet depending on page type, etc. are part of my design.

Here is the beginning template… I want to fill this in and nail down all the page types and identify them correctly. By doing so, there is a common IF/ELSE pattern that can be reused.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<txp:lang/>" lang="<txp:lang/>">
<head>

  <title> Detect page type and generate the appropriate title here </title>

  <meta name="description" content="if an article we get this from a custom field, else other page types it has to be generated depending on page type" />
  <meta name="keywords" content="if an article we get this from txp_keywords, else this has to be generated depending on page type" />
  <link rel="stylesheet" type="text/css" href="/themes/techno/reset.css"/>
  <link rel="stylesheet" type="text/css" href="/themes/techno/global.css"/>
  <link rel="stylesheet" type="text/css" href="Detect page type and generate the appropriate style sheet here (is it home.css, category.css, article.css, author.css, category.css?)" />

</head>
<body>
<div id="page">
  <div id="header">
    <h1><txp:sitename/></h1>
  </div>
  <div id="navbar">
    <txp:section_list wraptag="ul" break="li"/>
  </div>
  <txp:breadcrumb wraptag="div" class="breadcrumb"/>
  <div id="content">
    <div id="sidebar">
       Depends on page type and what you want to do
    </div>
    <div id="column">
       Detect page type and generate the appropriate title here...

       Generate home page
       Generate section home page
       Generate author page
       Generate category home page
       Generate search page
       Generate search result page
       Generate individual article page

    </div>
  </div>
  <div id="footer">
    <p id="copyright">Copyright &copy; Kobashi Computing. All rights reserved.</p>
  </div>
</div>
</body>
</html>

After fidding around with glx_if and standard Textpattern tags, there seems to be some overlap and things aren’t mutually exclusive in using just one tag.

Last edited by kkobashi (2008-08-12 06:47:44)


Kerry Kobashi
Kobashi Computing

Offline

#2 2008-08-12 08:03:03

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: How to identify all major page types in the default page template?

Because I’m lazy, I use:

<txp:php> echo output_form(array('form' => 's-'.section(array()))); </txp:php>

And with 4.0.7 we could directly use:

<txp:output_form form='s-<txp:section />' />

That would output unique from for each section.

Or if we want to play with conditionals (txp:if_section + txp:output_form), then it is possible too.

Offline

#3 2008-08-12 08:25:00

kkobashi
Member
Registered: 2008-01-27
Posts: 51
Website

Re: How to identify all major page types in the default page template?

No idea what you are trying to do Gocom. Makes no sense to me. I put that in my default page template and nothing was shown.

I am trying to nail down the exact IF/ELSE sequence to detemine each type of page uniquely in the default page.

For example:

<txp:glx:if_front_page>
<title><txp:site_name> | <txp:site_slogan/></title>
<meta name="description" content="Kobashi Computing is a Silicon Valley consulting company"/>
<meta name="keywords" content="consulting, Silicon Valley"/>
</txp:glx:if_front_page>
.
.
.
<txp:if_individual_article>
  <title><txp:site_name/> | <txp:title/></title>
  <meta name="description" content="<txp:custom_field name="description"/>" />
  <meta name="keywords" content="<txp:keywords/>"/>
</txp:if_individual_article>
.
.
.
<link rel="stylesheet" type="text/css" href="/themes/techno/reset.css"/>
<link rel="stylesheet" type="text/css" href="/themes/techno/global.css"/>
<txp:glx_if_frontpage>
  <link rel="stylesheet" type="text/css" href="/themes/techno/home.css"/>
</txp:glx_if_frontpage>
.
.
.
<txp:if_individual_article>
  <link rel="stylesheet" type="text/css" href="/themes/techno/article.css"/>
</txp:if_individual_article>

<body>

<txp:glx_if_frontpage>
   <h2>Welcome</h2>
   <p>Welcome to Kobashi Computing</p>
</txp:glx_if_frontpage>
.
.



</body>
</html>

In other words, capture each page type and do everything from the default page. THEN break things up and find commonalities and move to forms and sections/separate section page templates. Do you understand what I am trying to do?

I’ve seen recommendations on using <txp:if_section name=”“/> to detect front page but that seems to me to be bad advice. I’ve seen cases where category pages also have a no named section and this really doesn’t help me. Using GLX_IF there are also problems I see because it does not uniquely identify the home page and has fallen through other IF tags. So I am not confident these tags work well.

Last edited by kkobashi (2008-08-12 08:33:36)


Kerry Kobashi
Kobashi Computing

Offline

#4 2008-08-12 08:37:32

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: How to identify all major page types in the default page template?

kkobashi wrote:

No idea what you are trying to do Gocom. I put that in my default page template and nothing was shown.

Not trying, but doing with out redicilous amount of conditionals.

Ofcourse it doesn’t show anything as output_form outputs contents of forms, like PHP’s include includes a file. And because you don’t have form with the name, then it won’t output anything. But it will always just requestes unique form for each section, that name is based on the section name (in example s-default s-blog etc), and if the form is is found with correct name, then it will output it. You just have to make sure that you have made the form beforehand. You know, magic doesn’t exist ;)

Last edited by Gocom (2008-08-12 09:58:45)

Offline

#5 2008-08-12 08:52:13

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

Re: How to identify all major page types in the default page template?

Gocom’s right; trying to do it all in one page is going to get very messy, very quickly.

I have tried something like this before and quickly gave up since the nested <txp:else />s gave me a headache. But if you want to do it, the general structure is probably something like:

<txp:if_search>
  // call search results
<txp:else />

  <txp:if_author>
    // call author filter form
  <txp:else />

    <txp:if_category>
      // call category filter form
    <txp:else />

      <txp:if_section name="blah">
        // use gocom's solution instead here to call a form based on section name
        // otherwise you need a tonne of if_section calls

      <txp:else />

        <txp:glx_if_frontpage>
          // Front page form
        <txp:else />

          <txp:if_individual_article>
            // Article tag here
          <txp:else />
            // Article list tag here
          </txp:if_individual_article>

        </txp:glx_if_frontpage>

      </txp:if_section>

    </txp:if_category>

  </txp:if_author>

</txp:if_search>

Something horrible like that anyway! I would tend to always process search/category/author first and leave everything else till later.

Last edited by Bloke (2008-08-12 08:57:39)


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 2008-08-12 10:41:19

kkobashi
Member
Registered: 2008-01-27
Posts: 51
Website

Re: How to identify all major page types in the default page template?

Thanks Bloke. Yes, I fully realize that it would start to look messy. Apart from the ability to associate section to specific page template, this is what our Textpattern applications really look like, right? GoCom’s suggestion isn’t necessary because every section would either have a direct relationship with a page template or head to the default page template. That is, why bother taking on specific case by case? Imagine having hundreds of sections. I seriously doubt someone is going to go create distinct page layouts for each section – too much work to adminster, maintain, etc.

Its a nested piece of ugliness because the default page must handle everything uncommon to sections. Now what happens if the system extends itself with further page types? The nesting gets even more uglier making code readibility, if not maintenance less than desired for the application developer.

Why is there nesting at all? Why is this not flat? To me its a problem in the design and it starts right with the URI. What if life were this easy:

http://www.site.com/ => index page for site

http://www.site.com/users/ => index page for users
http://www.site.com/articles/ => index page for article
http://www.site.com/videos/ => index page for video
http://www.site.com/images/ => index page for images
http://www.site.com/search/ => index page for search

http://www.site.com/users/category/subcategory/title => user object
http://www.site.com/articles/category/subcategory/title => article object
http://www.site.com/videos/category/subcategory/title => video object
http://www.site.com/images/category/subcategory/title => image object

Every object publicly made available on the webserver has a unique URI signature. The URI parser should be able to pick apart the URI based on a system defined setting and fill in the page details:

$page[‘type’] – type of page (article, video, image, comment, search, etc)
$page[‘index’] – are we on a index page (yes/no)
$page[‘category’] – array of category/subcategories
$page[‘title’] – the title of the object

txp tags exist to look at the page attributes:
  • <txp:if_page_index type=“video”/>
  • <txp:if_page_list type=“image”/>
  • <txp:if_page type=“article”/>

Then life in the default page would be flat.

Last edited by kkobashi (2008-08-12 11:12:54)


Kerry Kobashi
Kobashi Computing

Offline

#7 2008-08-12 10:47:39

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

Re: How to identify all major page types in the default page template?

Although I’ve never used it, I believe the gbp_permanent_links plugin allows you to do stuff like that and make the TXP world more flat. I may be wrong.

Last edited by Bloke (2008-08-12 10:47:59)


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 2008-08-12 20:18:06

kkobashi
Member
Registered: 2008-01-27
Posts: 51
Website

Re: How to identify all major page types in the default page template?

Ok I got an issue here. I need to get the author name.

So for example in the default page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<txp:lang/>" lang="<txp:lang/>">
<head>

  <!-- metadata -->
  <txp:if_search>
    <title><txp:site_name/> | search</title>
    <meta name="description" content="Search the website" />
    <meta name="keywords" content="search, site search, search website"/>
  <txp:else/>
    <txp:if_author>
      <title><txp:site_name/> | <txp:author/> author profile</title>
      <meta name="description" content="Author information for <txp:author/>" />
      <meta name="keywords" content="<txp:author/>, <txp:author/> profile"/>
    <txp:else/>
.
.

When I type in:
http://www.mysite.com/author/Joe Schmoe

I do go to the author page but the <txp:author> tag doesn’t resolve – it is empty.
How does one generate Joe Schmoe’s author page using standard txp tags?


Kerry Kobashi
Kobashi Computing

Offline

#9 2008-08-13 04:36:37

kkobashi
Member
Registered: 2008-01-27
Posts: 51
Website

Re: How to identify all major page types in the default page template?

I’ve created a plug-in to detect all page types exclusively.

This plugin detects the following:

  • Article page
  • Home page
  • Author home page
  • Author page
  • Search home page
  • Category home page
  • Section home page
In addition it includes helpers:
  • Author real name
  • Author login name

It so far has made my code writing so much better, cleaner to read, and easier to maintain. Its also made everything flat.

I couldn’t get glx_if to work. After looking at the code and studying Textpattern behavior as the flow came into the default template page, I seriously doubt that the glx_if_frontpage mechanism is accurate. For example, one is on the home page when $pretext[‘request_uri’] is “/”. I also disagree with a forum post that was sent to me several months ago that to detect the home page that it was easy as the section name being empty. This is also incorrect from what I have observed.

Thus, I am refraining from using glx_if and consider it flawed. I will post this plug in when I have tested it more but so far, it is working perfect and the template code pattern is repeatable and easy to just “fill in the blanks”.

Last edited by kkobashi (2008-08-14 03:01:21)


Kerry Kobashi
Kobashi Computing

Offline

#10 2008-08-14 03:45:13

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: How to identify all major page types in the default page template?

GoCom’s suggestion isn’t necessary because every section would either have a direct relationship with a page template or head to the default page template. That is, why bother taking on specific case by case? Imagine having hundreds of sections. I seriously doubt someone is going to go create distinct page layouts for each section – too much work to adminster, maintain, etc.

Where did I say whole page templates? You can pull forms inside templates, so you can have unique keywords, titles, sidebars etc, with out 100*if_section+code mess.

In example the one and only page template:

<txp:output_form form="x-head" />
<txp:php> echo output_form(array('form' => 's-'.section(array()))); </txp:php>
<txp:output_form form="x-sidebar" />
<txp:output_form form="x-footer" />

And, then some forms:

s-default:

Hey, my homepage is here!
<txp:article limit="10" form="default" />

s-contact:

Here you see my contact form. Please contact.
<txp:zem_contact />

s-links:

My links, dude!
<txp:linklist />

And so on. I never said multiple page templates, i said forms, freaking forms with out messy conditional shit. In some cases that is way too good shortcut. Geez.

Last edited by Gocom (2008-08-14 03:47:31)

Offline

#11 2008-08-14 07:37:12

kkobashi
Member
Registered: 2008-01-27
Posts: 51
Website

Re: How to identify all major page types in the default page template?

Gocom:

How about you show me this entire if/else sequence and make sure that it works, eh? So far, I’ve not had any responses that Textpattern is capable of doing this and has proven to me that it works. In fact, I’ve had to go out and create a plug in to make this work. What does that say about the core functionality of Textpattern? If I have to reach for plugins (glx_if is not accurate) , resort to raw php, or worse yet create my own plugin, then that tells me Textpattern functionality is INCOMPLETE!

Especially when there should be a definite structure of identifying each and every type of page in the system in the default template.

And how does your solution uniquely identify the author page, the author index page, the catalog index page, search index page, etc. that I mentioned at the top of this thread? I don’t see it. Once again, I want to catch all page types in the default template and prove that it works. I could care less if it looks messy. I want to see if it can be done and see the pattern. Then, I will optimize and break apart into forms, and reuse the pattern.

Although I have considerable programming experience in PHP and other languages, I dont care about plug ins and the use of raw php at this point. I want to see what the existing Textpattern system can do via standard Textpattern txp tags. I am evaluating Textpattern to decide if I should use it. If I have to spend time hacking away forcing things to make basic things work, then that makes me less productive and takes me away from doing what I should be doing – providing content and building vistor views for my website instead of programming.

Last edited by kkobashi (2008-08-14 09:39:18)


Kerry Kobashi
Kobashi Computing

Offline

#12 2008-08-14 09:36:45

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

Re: How to identify all major page types in the default page template?

Hello again. Nice idea about the plugin but — sorry if I’m being dense here — I’m struggling to understand why you’d want to do this.

Are you saying you want to set up a site with one page template for every section, author, category, search, article, contact form and list on your site? So your site has exactly the same layout for every page regardless what the user is viewing and then use a heap of conditionals to detect what’s going on to display stuff from there?

I can understand putting, say, search and author — perhaps category — on your default page because it saves a few keystrokes when calling the tags, but to have the same page template for every section / index page, I don’t know, it seems to my limited brain remarkably inefficient to have to process a hunk of nested conditionals every time. Even as an academic exercise to see if it can be done, why do it when other tools are there to make life easier? Sections are linkable to page templates for a reason — there’s one catch-all for “misc” stuff (or your home page) and then each section gets its own identity thereafter.

When you refer to the “author home page”, do you mean when the url has just site.com/author in it? In which case — like categories and sections without article titles — that puts TXP in its “list” mode and is automatically detectable using the <txp:article /> tag with the listform attribute. Or, at a push, if_individual_article / if_article_list. You don’t need to “detect” a list because TXP’s article tag does it for you; only if you want to do something special do you need the conditionals. Coming from a PHP background, I struggled with that at first. I was like “so I don’t need to check what’s going on, TXP just ‘knows’ where it is…? Way cool!”

For example, if you route your ‘authors’ tags to a(ny) page template and do a simple <txp:if_author /> detection, the article tag in that branch will handle either a list of authors or an individual author situation without you doing anything more. Likewise with categories, searches, even the home page (in theory, though like you say, I could never figure why the site ‘root’ page was supposedly detectable with section="" when it was labelled “default” *shrug*)

For the record, I tend to write fairly similar pages — per section — and choose which of those are going to be my “landing pages” for various types of content: category, author, home page, whatever. Then I bung a conditional in there to detect that type and let the article tag handle it from there. My page templates are usually just lists of <txp:output_form /> tags. e.g.:

<txp:output_form form="dtd" />
<txp:output_form form="html_head" />
<txp:output_form form="page_head" />

<txp:if_something>
// blah blah header

  <txp:if_something_else>

  // blah blah header 2

  </txp:if_something_else>

</txp:if_something>

<txp:article form="my_article" listform="my_list" />

<txp:output_form form="page_foot" />

</body>
</html>

That way I can reuse the DTD and the headers and footer like PHP includes, put conditionals inside those forms if required for very specific tasks but keep the same basic page layout for most sections. Each section does usually have its own identity; <div> blocks in different places or in a different orientation, or a contact form for example, and I prefer that to be in a separate page than in one behemoth template. By consolidating stuff into forms and reusing them wisely you may well save yourself some bother instead of trying to do it all in one page first and then embracing forms.

I’d certainly investigate the power of the tags before trying to make the world flat, because it may save you (more) headaches. Just my 2p, but if I’ve grossly misunderstood your motive then I apologise.

P.S. forgive Gocom, his youthful brain’s far more inventive and lively than most of us and when he gets excited about a solution his writing style appears confrontational when it’s usually not intended that way; check his plugin docs/threads for proof. Believe me, if he was pissed off, you’d know it :-)

Last edited by Bloke (2008-08-14 09:42:57)


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

Board footer

Powered by FluxBB