Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#16 2015-06-19 13:44:04

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,446
Website GitHub

Re: Description field and tag

philwareham wrote #291709:

I’m fine with just <snip>

Suits me.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#17 2015-06-19 16:01:33

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,446
Website GitHub

Re: Description field and tag

Done a version which works well. Articles, cats and section descriptions all catered for. A single <txp:meta_description /> tag that takes three args:

  • escape (html or empty)
  • format (either tag to output the full meta tag or raw to just squirt out the content)
  • type (article, section or category. Defaults to the best fit based on context)

More testing to go, and I need to add the conditional tag which I don’t have time to do now, but if I get Internet access later I’ll see what I can do and maybe commit it for testing to 4.6.x.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#18 2015-06-19 17:27:00

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,565
Website GitHub Mastodon

Re: Description field and tag

Cheers Stef, this’ll make life much simpler!

Offline

#19 2015-06-22 09:28:59

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,638
Website

Re: Description field and tag

Thanks for implementing this, Stef! One more “complicated” little snippet can be put to rest and replaced by just a couple of lines of code.

With my editor-hat on, now I’m left with a slight problem: how to migrate a truckload of articles to make use of this…
(the site in question uses the excerpt field combined with an old plugin: jad_metadata)


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

Offline

#20 2015-06-22 09:43:02

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,446
Website GitHub

Re: Description field and tag

For anyone following this thread, descriptions for articles, sections and categories have landed in core. Two new tags support them:

<txp:meta_description>

Renders a <meta name="description" content="the content here" /> tag by default. Without any arguments it tries to pick up the context from wherever you use it:

  • If inside an individual article, it’ll output the article’s description.
  • Inside a <txp:category_list> or <txp:section_list> container/form it’ll output the relevant description from there.
  • If you’re on a /category landing page, it’ll use the category description from the corresponding content type.
  • Failing all that, if it’s used on a Page it’ll display the Section description.

The automatic detection can be overridden with the type attribute. You can set it to output the section or article value, or use category to output the current category description. There is also an extended syntax if you want to force the tag to output the category of a particular content type. For example, to display the image description from the currently selected category, use type="category.image".

Other attributes are format which takes either the default tag option to display the full HTML <meta> tag, or set it empty (or use raw or whatever you like really, it’s not fussy) to output the description without any markup.

The final attribute is escape which take the usual (default) html option to escape quotes and characters with their HTML entity equivalents, or set escape="" to render the description verbatim.

If the description in the selected / automatic context is empty, nothing is displayed.

<txp:if_description>

Uses exactly the same attributes as above and just allows you to take action if the given or automatic context contains a description or not. Supports <txp:else />.

Please take it for a spin in 4.x-dev if you’re able and report here on your findings.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#21 2015-06-22 09:48:03

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,446
Website GitHub

Re: Description field and tag

phiw13 wrote #291770:

how to migrate a truckload of articles to make use of this…

Yes, that’ll probably require flexing some SQL muscles to copy your excerpts in to the description for certain articles, taking into account:

  • No Textile support in the new field.
  • The 255 char limit.
  • You’ll need to empty out both excerpt and exceprt_html fields from each article upon successful migration of a description.

And then update your templates to use the new tags. Not exactly a walk in the park unfortunately.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#22 2015-06-22 09:56:32

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,565
Website GitHub Mastodon

Re: Description field and tag

Bloke wrote #291772:

For anyone following this thread, descriptions for articles, sections and categories have landed in core. Two new tags support them…

Isn’t it 3 new tags?

  • <txp:description />
  • <txp:if_description />
  • <txp:meta_description />

Offline

#23 2015-06-22 10:09:13

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,446
Website GitHub

Re: Description field and tag

philwareham wrote #291775:

Isn’t it 3 new tags?

Nope. I consolidated what was to become <txp:description /> into <txp:meta_description> to fit in with the other <txp:meta_* /> tags, and just allowed the raw value to be output via an attribute. So that tag fulfils both roles. It’s all meta data, regardless of how you (ab)use it in your Pages.

Kinda wanted to go with <txp:if_meta_description> for consistency with the main tag, but we already have <txp:if_keywords> so I dropped the meta bit to fit in with the conditional lineage.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#24 2015-06-22 10:14:34

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,565
Website GitHub Mastodon

Re: Description field and tag

Bloke wrote #291778:

Nope. I consolidated what was to become <txp:description /> into <txp:meta_description> to fit in with the other <txp:meta_* /> tags, and just allowed the raw value to be output via an attribute. So that tag fulfils both roles. It’s all meta data, regardless of how you (ab)use it in your Pages.

Kinda wanted to go with <txp:if_meta_description> for consistency with the main tag, but we already have <txp:if_keywords> so I dropped the meta bit to fit in with the conditional lineage.

Yeah but there is already a <txp:keywords /> tag hence the <txp:if_keywords>. Sorry I know you want to minimise additional tags I would really prefer there to be a <txp:description /> tag too (and remove the current attribute from meta_description) – what’s everyone else’s thoughts on this?

Offline

#25 2015-06-22 10:45:45

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,446
Website GitHub

Re: Description field and tag

philwareham wrote #291779:

Yeah but there is already a <txp:keywords /> tag hence the <txp:if_keywords>.

OK, yeah, I s’pose. So the conditional tag kinda serves to allow you to differentiate both tags. And the two tags do exactly the same thing, except one outputs formatted content, the other outputs raw.

We can play it either way. Or take the curveball and deprecate <txp:keywords> in favour of adding a format attribute to <txp:meta_keywords>. The existing <txp:keywords> tag in use in people’s templates would then just throw a warning in testing mode (but would still work), acting as a stub for <txp:meta_keywords format="raw" />.

EDIT: Or vice versa: keep <txp:keywords> and <txp:description> with format attributes and remove the <txp:meta_*> variants (though what to do with <txp:meta_author>… deprecate that too and add a format attribute to the <txp:author> tag?)

Don’t mind either way. Whatever the community prefers.

Last edited by Bloke (2015-06-22 10:48:02)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#26 2015-06-22 10:50:10

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,565
Website GitHub Mastodon

Re: Description field and tag

Bloke wrote #291783:

We can play it either way. Or take the curveball and deprecate <txp:keywords> in favour of adding a format attribute to <txp:meta_keywords>. The existing <txp:keywords> tag in use in people’s templates would then just throw a warning in testing mode (but would still work), acting as a stub for <txp:meta_keywords format="raw" />.

Sure, that could work too. I guess keywords are ‘meta’…

“Meta is a prefix used in English to indicate a concept which is an abstraction from another concept, used to complete or add to the latter.” – Wikipedia

Offline

#27 2015-06-22 14:04:30

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,446
Website GitHub

Re: Description field and tag

I’m tempted to rethink this meta lark a bit. 4.6.x introduces <txp:author url="1" /> for displaying the author as a raw link instead of a name. What about if we tried to standardise things a tad:

  • <txp:author format="url" /> (instead of <txp:author url="1" />). It’s more readable if nothing else.
  • <txp:author format="meta" /> (same as <txp:meta_author />, except it won’t return empty if there’s no author at present).
  • <txp:author format="link" /> (instead of <txp:author link="1" />, outputs a linked author name).
  • add escape="html" attribute so you have the option to output the author raw.

That would have a knock-on effect for standardisation that we would:

  • have <txp:description format="meta" /> (instead of the proposed format="tag" attribute).
  • ditch <txp:meta_description />, or use it as a shortcut to the above.

And:

  • have <txp:keywords format="meta" /> (same as <txp:meta_keywords> without the check to see if it’s empty. Alternatively, deprecate the meta-specific tag).
  • add escape="html" to the <txp:keywords/> tag for output flexibility.

Using format="link" fits in with the <txp:css>, <txp:feed_link> and <link_feed_link> tags. But it does mean that we might consider the same attribute in place of link="1" in <txp:thumbnail>, <txp:link_author>, <txp:link_category>, <txp:comment_name>, <txp:author_email>, <txp:category>, <txp:category1>, <txp:category2>, <txp:section>, <txp:image_author>, <txp:file_download_author>, and <txp:breadcrumb>. It also scuppers <txp:image_url> slightly as that has an link="auto" option. And does it clash with the ‘date-based’ usage of format in the posted, modified, expires tags? (although we have those already alongside other format attributes).

So maybe it’s not such a good idea, but I dunno. I’m not talking about removing the attributes, just deprecating them and moving towards fewer, more standardised attributes. Is that a long-term goal?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#28 2015-06-22 14:22:40

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,565
Website GitHub Mastodon

Re: Description field and tag

I don’t know – that sounds more complicated to me. I’d be OK with deprecating <txp:keywords> and having the format="raw" on the <txp:meta_keywords> and <txp:meta_description> as suggested previously. The keywords and description appear in the meta section of the Write page after all, so the tags are quite self-explanatory.

Offline

#29 2015-06-22 14:42:14

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,446
Website GitHub

Re: Description field and tag

philwareham wrote #291812:

format="raw" on the <txp:meta_keywords> and <txp:meta_description> as suggested previously.

Yeah, that’s the inverse of the above. And equally valid, it’s just that if we’re considering deprecating <txp:keywords>, and using <txp:meta_description> instead of <txp:description>, where does that leave <txp:author>? It’s sort of a special case in a way, that just happens to have a companion <txp:meta_author> for specific meta-usage. But that’s why I considered keeping the ‘non-meta’ versions with an attribute, versus keeping the meta versions, ditching keywords and also having an author tag.

I’m equally fine with keeping both the ‘meta’ and ‘non-meta’ versions of all three tags, so having six tags in three pairs. Maybe adding format="meta" to each of the non-meta variants too. That would then mean more than one way to produce a desired result, which could be regarded as a boon or a potential source of confusion / bloat.

Not sure. Changing the tag handlers to be more consistent isn’t hard, it’s just whether we want to consider it. I don’t want to introduce a format="tag" attribute for the sake of it when it’s the only tag using it, but then <txp:meta_description format="meta" /> seems over-wordy and largely redundant. I like format="raw" or format="" though, if we keep the <txp:meta_*> tags.

Hmmmmmmmm.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#30 2015-06-22 14:56:07

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,565
Website GitHub Mastodon

Re: Description field and tag

Actually format="" is pretty good idea, it’s got previous history on other tags’ syntax.

I’m still leaning towards deprecating <txp:keywords> tag.

<txp:author> has other uses outside of meta stuff, so I don’t see that as an inconsistency.

Offline

Board footer

Powered by FluxBB