Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

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

Re: Description field and tag

That could work, I only suggested meta_description because of consistency with the existing meta_keywords, meta_author tags.

Offline

#14 2015-06-19 13:26:45

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

Re: Description field and tag

philwareham wrote #291705:

That could work, I only suggested meta_description because of consistency with the existing meta_keywords, meta_author tags.

Ah yes. Your suggestion is better and more consistent. Having a dedicated tag to output <meta name="description" content="field content" /> is definitely more consistent with what we have already. And self-documenting :-)

In which case, do we go with:

  • <txp:meta_description> (with attributes)
  • <txp:description> (with attributes)
  • <txp:meta> (with attributes)
  • <txp:something_else_entirely ... >?

to output the more general form of the tag? I’ve got no real preference either way, it’s whatever you think is least confusing / more natural. If we went with one of the latter three options, under the hood I’d make the <txp:meta_description /> tag a stub that called the generic tag with the correct attributes to render the desired form. Less code that way.


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

Online

#15 2015-06-19 13:34:33

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

Re: Description field and tag

I’m fine with just…

  • <txp:meta_description> (with attributes)
  • <txp:description> (with attributes)

…to be honest. If someone wants to code some Open Graph or a Twitter Card, etc they can use the <txp:description> something like so:

<meta property="og:description" content"<txp:description>" />
<meta name="twitter:description" content="<txp:description>" />

Offline

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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
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.

Txp Builders – finely-crafted code, design and Txp

Online

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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
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.

Txp Builders – finely-crafted code, design and Txp

Online

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

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
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: Japan
Registered: 2004-02-27
Posts: 3,194
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

Offline

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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
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.

Txp Builders – finely-crafted code, design and Txp

Online

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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
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.

Txp Builders – finely-crafted code, design and Txp

Online

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

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
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: 11,448
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.

Txp Builders – finely-crafted code, design and Txp

Online

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

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
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

Board footer

Powered by FluxBB