Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Metadata snafu in TXP 4.2.0
I’m using the design pattern for dynamic metadata described by Kevin Potts in Textpattern Solutions— this involves using Textpattern’s conditionals to output article-specific description and meta_keywords on individual article pages, and delivering the same metadata for a sticky article when the context is a section landing page. This design pattern has worked for ages, but yesterday I noticed that a site that I recently upgraded to TXP 4.2.0 is no longer publishing meta_keywords associated with the sticky articles on section landing pages.
It also failed to render keywords when I did the long-form <txp:if_keywords><meta name="keywords" content="<txp:keywords/>"/></txp:if_keywords>
, with the if_keywords
conditional evaluating as false in the tag-trace. Displaying txp:keywords in article context within the body element worked without error.
So I made a clean install from the SVN to test the same code in the default template, and came up with flakey results— Textpattern’s txp:meta_keywords
seems to output nothing in any context, even though I’ve added keywords to each relevant article (and added sticky articles where needed).
Clearly, I must be doing something wrong, right?
Here’s the conditional logic I used on the sandbox install:
<title><txp:page_title /></title>
<!-- Metas
<txp:if_section name="">@ home -->
<txp:article_custom section="home" status="sticky" limit="1" form="_metas-dynamic"/>
<!-- you got sticky -->
<txp:else/>
<txp:if_individual_article>@ article -->
<txp:article form="_metas-dynamic"/>
<!-- you got live -->
<txp:else/>@ list -->
<txp:article status="sticky" limit="1" form="_metas-dynamic"/>
<!-- you got sticky -->
</txp:if_individual_article>
</txp:if_section>
And here is the code in my article-type form _metas-dynamic
:
<meta name="description" content="<txp:section/>: <txp:title/>; Categories: <txp:category1/> <txp:category2/> "/><!-- you got described -->
<txp:meta_keywords/><!-- you got keyworded -->
In the wild, I use rss_auto_excerpt to generate the description, and I also include conditional logic to generate an appropriate author meta element— but here, I wanted to focus on the keywords issue. So here is the output I get:
Home page (section “default”)
<!-- Metas
@ home -->
<meta name="description" content="home: Homepage title; Categories: meaningful-labor "/><!-- you got described -->
<!-- you got keyworded -->
<!-- you got sticky -->
Tag trace:
<txp:if_section name="">
[<txp:if_section name="">: true]
<txp:article_custom section="home" status="sticky" limit="1" form="_metas-dynamic"/>
[SQL (0.00049090385437): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from test_textpattern as textpattern where 1=1 and Status = 5 and Posted <= now() and (now() <= Expires or Expires = '0000-00-00 00:00:00') and Section IN ('home') order by Posted desc limit 0, 1]
[article 2]
[SQL (0.000154972076416): select Form from test_txp_form as txp_form where name='_metas-dynamic']
[Form: _metas-dynamic]
<txp:section/>
<txp:title/>
<txp:category1/>
<txp:category2/>
<txp:meta_keywords/>
</txp:if_section>
Section landing page (section “articles”)
<!-- Metas
@ list -->
<meta name="description" content="articles: Article landing page!; Categories: hope-for-the-future "/><!-- you got described -->
<!-- you got keyworded -->
<!-- you got sticky -->
Tag trace:
<txp:if_section name="">
[<txp:if_section name="">: false]
<txp:if_individual_article>
[<txp:if_individual_article>: false]
<txp:article status="sticky" limit="1" form="_metas-dynamic"/>
[SQL (0.000533103942871): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from test_textpattern as textpattern where 1=1 and Status = 5 and Posted <= now() and (now() <= Expires or Expires = '0000-00-00 00:00:00') and Section IN ('articles') order by Posted desc limit 0, 1]
[article 3]
[SQL (0.000164985656738): select Form from test_txp_form as txp_form where name='_metas-dynamic']
[Form: _metas-dynamic]
<txp:section/>
<txp:title/>
<txp:category1/>
<txp:category2/>
<txp:meta_keywords/>
</txp:if_individual_article>
</txp:if_section>
Individual article (“Welcome to Your Site!”)
<!-- Metas
@ article -->
<meta name="description" content="articles: Welcome to Your Site!; Categories: hope-for-the-future meaningful-labor "/><!-- you got described -->
<!-- you got keyworded -->
<!-- you got live -->
Tag trace:
<txp:if_section name="">
[<txp:if_section name="">: false]
<txp:if_individual_article>
[<txp:if_individual_article>: true]
<txp:article form="_metas-dynamic"/>
[SQL (0.000304222106934): select Form from test_txp_form as txp_form where name='_metas-dynamic']
[Form: _metas-dynamic]
<txp:section/>
<txp:title/>
<txp:category1/>
<txp:category2/>
<txp:meta_keywords/>
</txp:if_individual_article>
</txp:if_section>
Did something change in the way these tags work, or is there some obvious error in my usage? Thanks for your thoughts!
Last edited by johnstephens (2009-10-06 16:02:09)
Offline
Re: Metadata snafu in TXP 4.2.0
Maybe it is the lack of whitespaces at the and of an tag. E.g. <txp:keywords />
instead of <txp:keywords/>
?
Digital nomad, sailing the world on a sailboat: 32fthome.com
Offline
Re: Metadata snafu in TXP 4.2.0
Thanks— tested. Whitespace or no whitespace has no effect.
Edit: I’m aware that some txp:tags don’t work without the trailing space, but those tags don’t use Textpattern’s tag parser, according to Robert.
Last edited by johnstephens (2009-10-06 16:26:29)
Offline
Re: Metadata snafu in TXP 4.2.0
Okay, I’ve tested this same markup in a vanilla install of Textpattern 4.0.8, and I’m getting similar results— which means there is definitely a problem with the code.
I’m sure I had this working in recent memory, though. Time to pore through the site’s version history and see when things went amiss.
If anyone sees the error right off, feel free to let me know!
Offline
Re: Metadata snafu in TXP 4.2.0
snafu
adj : snarled or stalled in complete confusion; “situation normal—all fucked-up” [syn: fucked-up] n : an acronym often used by soldiers in World War II: situation normal all fucked up v : cause to be in a state of complete confusion
Interesting!
Two esoteric long-shots:
- what about trying a different form name? The
_metas-dynamic
looks OK for me, but then, who knows? That initial_underscore
may be better kept as a secret until shaman powers need to be invoked - what about the way you are breaking comments apart (keeping one half outside and one half inside the conditional)? I know TXP is not too draconian about syntax (tags-in-tags may be seen as a sin by xml advocates), but then, you are playing with
<!-- fire -->
.
Offline
Re: Metadata snafu in TXP 4.2.0
Underscores in form names are OK.
Offline
Re: Metadata snafu in TXP 4.2.0
Understood, wet!
Sorry for triggering any false alarm!
Offline
Re: Metadata snafu in TXP 4.2.0
Thanks Julián, Robert. I’ve used leading underscores in all my form names on every project, and if that suddenly becomes a problem, I think the results would be more dramatic.
I just removed the HTML comments in order to test the output without them, and that didn’t have any effect on Textpattern tag output: I still get keywords output in the if_individual_article
context, but nowhere else.
The other two tags that call this form include status="sticky"
and limit="1"
attributes. I use the same method to display the right content in the main part of a generic page, and it works fine:
<txp:if_article_list>
<txp:article limit="1" status="sticky"/>
<txp:else/>
<txp:article/>
</txp:if_article_list>
Keywords that show up in the default
article form turn up fine.
I have no idea what is amiss.
Offline
Re: Metadata snafu in TXP 4.2.0
johnstephens wrote:
I still get keywords output in the
if_individual_article
context, but nowhere else.
I had a cursory look at this and tried your code on my own test site. I got keywords out when in a regular individual article as expected (as keywords and meta_keywords are supposed to only show up in individual article pages; looks like they’re ignored in article list context. Perhaps in the default
form they’re not ignored but they are everywhere else… surely not!?)
However, mucking about with the sticky status did generate some weird results with your code. I’ll have to dig deeper to find out any more once I suss out what I expect to happen when running your examples on the various pages.
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
Re: Metadata snafu in TXP 4.2.0
Thanks for looking into it, Stef! This design pattern has worked for me up until very recently— and it obviously worked for Kevin too, or I don’t imagine he would have printed it in Textpattern Solutions. I must have changed the code in some elusive way that I’m not seeing, because Kevin’s Graphic Push site is still generating keywords for the homepage and section landing pages.
Offline
Re: Metadata snafu in TXP 4.2.0
AHA!
I decided to unzip a copy of Textpattern 4.0.7 to test this some more— since that’s the last version that I remember hearing Kevin publicly announce upgrading on his site. When that yielded pretty much the same results, I edited my form _metas-dynamic to test a few variations:
<txp:meta_keywords/> <!-- txp:meta_keywords -->
<meta name="keywords" content="<txp:keywords />"/> <!-- txp:keywords -->
<txp:if_keywords><!-- txp:if_keywords TRUE -->
<meta name="keywords" content="<txp:keywords />"/>
<txp:else/><!-- txp:if_keywords FALSE -->
</txp:if_keywords>
This gives me close to identical results in Textpattern 4.0.7, 4.0.8, and 4.x (svn)— I say “close to identical” because 4.0.7 and 4.0.8 return a tag warning on the txp:keywords
tag (when in Testing mode), and I haven’t seen that warning in 4.x. The warning appears in any context other than rendering an individual article page1:
Tag error: <txp:keywords /> -> Textpattern Notice: Article tags cannot be used outside an article context on line 2078
But here is what renders:
<!-- txp:meta_keywords -->
<meta name="keywords" content="home,key,words"/> <!-- txp:keywords -->
<!-- txp:if_keywords TRUE -->
<meta name="keywords" content=""/>
This is interesting:
- meta_keywords returns nothing, which has been its habit throughout these experiments.
- keywords renders fine, when outside the
if_keywords
conditional. - if_keywords evaluates as true, but…
- A
keywords
tag contatined in theif_keywords
conditional fails to render.
Anyway, this solves my problem— <meta name="keywords" content="<txp:keywords />"/>
outside of an if_keywords
conditional is the way to go. All other paths lead away from salvation.
Bloke wrote:
looks like [keywords and meta_keywords are] ignored in article list context
But wouldn’t using them within a form called by article
or article_custom
give them article context? As far as I can tell, all the other article tags are rendered in article or article_custom forms, regardless of the context in which the article tag appears. Is there a good reason keywords should not conform to this standard?
Thanks everyone for pushing me to the next level. If anyone can offer any insight into the workings of this, I’d love to know.
1 Debugging mode provides the following additional info:
textpattern/lib/txplib_misc.php:2078 trigger_error()
textpattern/publish/taghandlers.php:2296 assert_article()
textpattern/publish.php:1090 keywords()
textpattern/publish.php:1012 processTags()
textpattern/publish.php:499 parse()
index.php:33 textpattern()
Offline
Re: Metadata snafu in TXP 4.2.0
I would bet that this issue is somehow related to this other issue, and that it’s about time to have a core developer to take a look at it.
Offline