Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2015-06-19 13:02:31

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

Re: Description field and tag

philwareham wrote #291698:

<txp:meta_description /> tag… in addition to a <txp:description /> tag that just outputs the raw field value

If that’s what you want, sure. I’d prefer fewer tags as it’s less code, but the user needs outweigh that ;-)

They’d still need an attribute to select between section, category and article description (assuming we go for those too, which makes sense).

An alternative proposition:

Tag Output
<txp:meta name="description" type="article" /> <meta name="description" content="article field content" />
<txp:meta name="description" type="section" /> <meta name="description" content="section field content" />
<txp:meta type="article" /> article field content
<txp:meta property="og:title" type="article" /> <meta property="og:title" content="article field content" />

and so forth. If possible, the type should be optional since it’s probably possible to detect it from context, i.e. if in individual article context, type="article" by default, if inside a <txp:if_category> block, then set type="category" by default, else set type="section". So you’d only need to override it if you’re doing something out of the ordinary.

Edit: Maybe the name="description" could be default so you only need to use <txp:meta /> in most cases. And if you want to output the raw value, you use <txp:meta name="" />. Less typing, but a bit counter-intuitive maybe? Presumably property and name are mutually exclusive? [EDIT2: According to MDN there is no property attribute… urk]. In which case, specifying a property attribute would automatically set name="" so it didn’t output the name attribute when specifying OpenGraph or other meta content.

Any other attributes that the HTML meta tag can output which are of use here?

uli wrote #291699:

Cooked, so that apostrophes can’t do any harm.

Sorry, when I meant cooked, I meant with markup (like the <txp:article_image> and <txp:css /> tags do by default), as opposed to the raw value. But you’re right it would need an escape="html" attribute too.

Last edited by Bloke (2015-06-19 13:12:57)


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

#12 2015-06-19 13:06:30

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: Description field and tag

Bloke wrote #291703:

If possible, the type should be optional since it’s probably possible to detect it from context.

Yes, I would prefer on my side.


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

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

philwareham
Core designer
From: Farnham, Surrey, UK
Registered: 2009-06-11
Posts: 3,199
Website

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: 8,787
Website

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

Offline

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

philwareham
Core designer
From: Farnham, Surrey, UK
Registered: 2009-06-11
Posts: 3,199
Website

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: 8,787
Website

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

Offline

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

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

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

Offline

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

philwareham
Core designer
From: Farnham, Surrey, UK
Registered: 2009-06-11
Posts: 3,199
Website

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: 1,716
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)

Offline

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

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

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

Offline

Board footer

Powered by FluxBB