Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2019-03-10 14:21:19

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: [solved] Dates in my <head>

Destry wrote #316960:

If I try using that snippet exactly, I get this output:

<meta name="published" content="">...

Empty content attribute.

etc’s suggestion looks good. Can you clarify in what context that doesn’t work (an article, a list page? Perhaps also try and see if you get any output from the tags when not wrapped in the variable. You should at least be getting output on an individual article page.


TXP Builders – finely-crafted code, design and txp

Offline

#14 2019-03-10 14:33:53

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: [solved] Dates in my <head>

jakob wrote #316964:

Can you clarify in what context that doesn’t work . . . an article, a list page?

Like a lot of people, I’m guessing, I have my templates parsed into pieces that get joined up on render. This particular piece is in the tmpl_meta, itself called inside the tmpl_opener piece that’s common to all pages and sections.

For this particular site, I have a 1:1 section:page relation because the site is so small.

Nevertheless the top-most (e.g. the meta stuff) and bottom-most parts of the templates are common across them all.

At the body level, I have only two different article forms: one for ‘static’ pages, like I’m testing on now, and one for notes (somewhat equivalent to a blog). The latter shows the author and post date, so it’s not relevant in this case… Though now that I think of it, maybe that’s a conflict against the static pages sharing the same meta form.

Make sense? Maybe I need two different meta forms and a conditional to juggle them? Though I don’t see why I can’t get this work on the common form, but I’m hardly one to be confident about anything I’m doing these days.

Offline

#15 2019-03-10 15:13:48

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

Re: [solved] Dates in my <head>

The URL should give you an indicator. Assuming you’re using /section/title permlinks then if your URL is just /section, Txp will be in article list (a.k.a. landing page) context, regardless of whether you have told your <txp:article /> tag to output just one article and to display its body content or whatever.

This is often the case on contact pages where you have one article in the Section. On a typical (fairly new out of the box) site, visiting example.org/contact may render your ‘article-list’ Form, requiring you to click on the <h1> tag to visit the actual article (perhaps at example.org/contact/get-in-touch).

To get round this, I sometimes have a “one-article” Form that I use on Sections that only have one article. This Form is called as follows:

<txp:if_section name="list, of, sections, with, one, article">
    <txp:article form="one-article" limit="1" />
<txp:else />
    <txp:article />
</txp:if_section>

The one-article Form is coded to display the full body copy text, so even at the /contact landing page, visitors see everything as if the URL represents an individual article. Further, I remove the anchor on the heading so the ‘real’ article URL is masked from search engines and therefore doesn’t incur the wrath of duplicate content.


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

#16 2019-03-10 17:56:25

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

Re: [solved] Dates in my <head>

Destry wrote #316960:

If I try using that snippet exactly, I get this output:

<meta name="published" content="">...

Empty content attribute.

If you are on 4.7.2+, the only reason I can see is that you have no live articles on the concerned landing page. You can try to append status="sticky" attribute to <txp:article /> if the dates are pulled from there. In this case pageby="0" is not needed.

Offline

#17 2019-03-10 18:04:54

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

Re: [solved] Dates in my <head>

There is also a more efficient way, sparing a db query. Put this in the meta generating form:

<txp:hide process="2">
<meta name="published" content='<txp:variable name="posted" />'>
</txp:hide>

and the variable definition in the article form outputting the “main” article:

<txp:if_first_article>
    <txp:variable name="posted" value='<txp:posted />' />
</txp:if_first_article>

Offline

#18 2019-03-10 23:23:39

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: [solved] Dates in my <head>

Bloke wrote #316967:

The one-article Form is coded to display the full body copy text, so even at the /contact landing page, visitors see everything as if the URL represents an individual article.

Thanks for that perspective. It helped. I actually had something overall similar, I think, but my body snippet was this:

<txp:if_article_list>
    <txp:article status="sticky" form="simple_article" />
<txp:else />
    <txp:article status="live" form="simple_article" />
</txp:if_article_list>

I don’t know where I came up with that, exactly. I think it might have been something I reused from out-of-box?

Anyway, I adjusted to your example using if_section and changing limit="1" to status="sticky" and it seems to work fine:

<txp:if_section name="about, policies, contact, guide">
    <txp:article form="article_simple" status="sticky" />
<txp:else />
    <txp:article />
</txp:if_section>
etc wrote #316973:

the only reason I can see is that you have no live articles on the concerned landing page. You can try to append status="sticky" attribute to <txp:article /> if the dates are pulled from there.

And making that one little change to status="sticky" did the trick. The missing key. And I dropped limit="1". I assume that’s okay. It seems to work, since sticky is in the driver’s seat.

But, I want both posted and modified, so I’m doubling up on the markup now:

<txp:variable name="posted" escape="trim">
  <txp:if_article_list>
    <txp:article status="sticky"><txp:posted /></txp:article>
  <txp:else />
    <txp:posted />
  </txp:if_article_list>
</txp:variable>

<txp:variable name="modified" escape="trim">
  <txp:if_article_list>
    <txp:article status="sticky"><txp:modified /></txp:article>
  <txp:else />
    <txp:modified />
  </txp:if_article_list>
</txp:variable>

<meta name="published" content="<txp:variable name="posted" />">
<meta name="modified" content="<txp:variable name="modified" />">

That works, but I still wonder if something like this could be cooked up in the future, where each tag could take a string="" attribute for custom date formats:

<txp:meta_publish />
<txp:meta_modified />

But I’m sure it’s more complex than that.

I’m happy regardless. Thanks, all. I appreciate your patience/diligence.

Offline

#19 2019-03-11 09:38:28

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

Re: [solved] Dates in my <head>

Glad you got it solved. I would just define both dates in one <txp:article /> call:

<txp:if_article_list>
    <txp:article status="sticky" limit="1">
        <txp:variable name="posted"  value='<txp:posted />' />
        <txp:variable name="modified"  value='<txp:modified />' />
    </txp:article>
<txp:else />
    <txp:variable name="posted" value='<txp:posted />' />
    <txp:variable name="modified"  value='<txp:modified />' />
</txp:if_article_list>
Destry wrote #316979:

That works, but I still wonder if something like this could be cooked up in the future, where each tag could take a string="" attribute for custom date formats:

<txp:meta_publish />...

But I’m sure it’s more complex than that.

Yep, it looks complicated for article lists where we have to decide where the dates come from: live/sticky articles? which ones?

Offline

Board footer

Powered by FluxBB