Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
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.

Offline

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

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,058
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…


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

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

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

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
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
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?’

Offline

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

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

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: 11,250
Website GitHub

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
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
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.

Offline

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

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

Re: [solved] Dates in my <head>

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

Offline

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

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

Re: [solved] Dates in my <head>

Example modified to avoid re-pagination.

Offline

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

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
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.

Offline

#11 2019-03-10 13:33:36

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

Re: [solved] Dates in my <head>

Maybe we just need a couple new tags:

  • meta_published
  • meta_modified

:)

Offline

#12 2019-03-10 13:57:34

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

Re: [solved] Dates in my <head>

Just to explain why I’m pursuing this…

As I detail my policies, that govern all Websites on the wion domain, and notably those policies in this case concerning copyrights, I’ve become more aware from research that depending on the kind of license a given ‘Material’ has, it influences whether one cites a source in the course of ‘fair dealing’ or give attribution. The two are not the same, though it really depends what the context of use is.

In the case of citing — which is a specific ‘exception’ of use in French law to which the author can not interfere (not a ‘fair dealing’ exactly, but similar) — whether as a note or biblio entry or both, not all online resources have the same reference structure. At least not according to the Oxford style, which is what I use, but Chicago has a plethora of reference structure differences too. These are just some of the different formats in the OSM:

  • Online article
  • Online reference (e.g. Encyclopedia Brittanica)
  • Online interview
  • Wiki page (e.g. Wikimedia)
  • Blog post
  • News article (e.g. via The Guardian)
  • Journal article (i.e. academic journal)

Oddly, among all the examples given, there is no specific reference for:

  • ‘online periodical’ (e.g. a magazine article)
  • ‘general webpage’ (e.g. About, History, Policies…)

So one has to fake it a bit by pulling from the closest options. In the case of a general webpage — though static, is nevertheless revised occasionally — where there is usually no specific author or publish date on the top, it’s convenient to add that info as metadata. Then someone can still find what they need to create a proper reference and satisfy legal obligations to cite source copyrighted information correctly, for example

Wion, Destry, ‘Policies’, wion.com (last modified 10 March 2019), https://wion.com/policies, accessed 23 March 2019.

In these cases the ‘last modified’ date are somewhat important when the information is of a critical nature (e.g. Policies) and subject to change through time.

Offline

Board footer

Powered by FluxBB