Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-03-09 22:33:12

Destry
Moderator
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,233
Website

[solved] Dates in my <head>

Is it possible to do something like this?

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

Trying it like that gives me today’s date in both cases, which is wrong in the posted context, thus I suspect is a false positive in the modified context for fact it might just be defaulting to today’s date.

I see they’re not in article context… Do I need to setup an evaluate, or something sneaky?

I’m doing this as a possible workaround to provide dates for attribution/citation reasons for pages, like section defaults, where I don’t want author/date ugliness on the surface.


The text persuades, the *notes prove。

Offline

#2 2019-03-10 09:23:35

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 1,712
Website

Re: [solved] Dates in my <head>

On individual article pages, I use something like you do and it works fine. Purpose is to get dates inside a JSON snippet.

Hmm, reviewing my code:

<txp:hide process>
<!-- create a variable to check if article has been modified -->
<txp:variable name="modified" value='<txp:modified />' /></txp:hide>
… [snip]
"datePublished": "<txp:posted format='iso8601' />",<txp:if_variable name='modified' value='<txp:posted />'><txp:else />
  "dateModified": "<txp:modified format='iso8601' />",</txp:if_variable>

Not sure right now why I use the variable, though. My memory is playing tricks…

Offline

#3 2019-03-10 10:06:52

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,785
Website

Re: [solved] Dates in my <head>

Destry wrote #316946:

I see they’re not in article context…

They should be – they’re not supposed to return anything if not. Can’t see any reason why they shouldn’t output what you expect.


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

#4 2019-03-10 10:54:14

Destry
Moderator
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,233
Website

Re: [solved] Dates in my <head>

Bloke wrote #316950:

They should be

I know. Bad me. So I just need to figure out the evaluate trick then. I think I have something like that elsewhere for a different reason. I’ll see if it still makes sense. More likely I’ll be like phi… ‘What the hell is going on here?’


The text persuades, the *notes prove。

Offline

#5 2019-03-10 12:43:23

etc
Developer
Registered: 2010-11-11
Posts: 3,346
Website

Re: [solved] Dates in my <head>

Destry wrote #316946:

I see they’re not in article context…

In this case posted is undefined, which yield the current time by default.

Do I need to setup an evaluate, or something sneaky?

You need to pull these data from some article, like this:

<txp:variable name="posted" escape="trim">
<txp:if_article_list>
    <txp:article limit="1" pageby="0"><txp:posted /></txp:article>
<txp:else />
    <txp:posted />
</txp:if_article_list>
</txp:variable>

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

You’d need to reset pagination though, or rather use pageby="0" attribute.

Offline

#6 2019-03-10 12:43:56

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,785
Website

Re: [solved] Dates in my <head>

Destry wrote #316953:

I just need to figure out the evaluate trick then.

Sorry, when I said ‘they should be’ I meant that if you’re seeing something and there are no errors on the page in testing/debugging mode then they’ll be in article context. Otherwise you’ll get errors because those tags check article context as the very first thing they do and (should) complain if not. I didn’t realise they emit today’s date if outside article context. Must be a reason for that.

Wrapping the tag(s) in <txp:evaluate> may only guard against situations if the tags are used outside of article context. And even then I’m not sure how evaluate will behave because the posted/modified tags spit out an error, which could be deemed “content” by the <txp:evaluate> tag.

You’re better off ensuring that you only putting those tags in an article context, or wrap them in <txp:if_individual_article> to be sure, and output nothing otherwise.

EDIT: what Oleg said!

Last edited by Bloke (2019-03-10 12:47:45)


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

#7 2019-03-10 13:09:50

Destry
Moderator
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,233
Website

Re: [solved] Dates in my <head>

Thanks, guys. I was just trying this as you were writing, but it’s not working, nothing outputs at all.

<txp:hide process>
    Get our head dates on.
   <txp:variable name="posted" value='<txp:posted />' />
   <txp:variable name="modified" value='<txp:modified />' />
</txp:hide>
<txp:variable name="posted" escape="trim">
  <txp:article limit="1">
    <meta name="published" content="<txp:posted />">
  </txp:article>
</txp:variable>
<txp:variable name="modified" escape="trim">
  <txp:article limit="1">
    <meta name="modified" content="<txp:modified />">
  </txp:article>
</txp:variable>

I want both dates to appear. They would also be the same if the page was never modified since publishing, which is not the case on the test page I’m using.

Maybe the if_article_list part is the missing key. I’ll try that.


The text persuades, the *notes prove。

Offline

#8 2019-03-10 13:13:14

Destry
Moderator
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,233
Website

Re: [solved] Dates in my <head>

Oh, etc’s example is a bit different. I’ll restructure.


The text persuades, the *notes prove。

Offline

#9 2019-03-10 13:16:19

etc
Developer
Registered: 2010-11-11
Posts: 3,346
Website

Re: [solved] Dates in my <head>

Example modified to avoid re-pagination.

Offline

#10 2019-03-10 13:21:56

Destry
Moderator
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,233
Website

Re: [solved] Dates in my <head>

etc wrote #316959:

Example modified to avoid re-pagination.

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

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

Empty content attribute.


The text persuades, the *notes prove。

Offline

Board footer

Powered by FluxBB