Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-06-22 16:01:40

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

Bibliography management

If I want to use the otherwise useless newly-found interesting links panel to create a site-wide bibliography — each ‘link’ being an item in the bibliography list — what are my options for making link data more granular and flexible for the task?

I could make it work now by dumping most of a citation’s details into the Description field, which is not very content-management like, but the fact I can’t make the URL field conditional output screws it up. (Would smd_if do that?) The reason being, sometimes it’s used for DOI links, or other URLs when a source is freely available, but often there is no link to give. So I need conditional output on that field (e.g. <txp:if_link_url />).

I could then do something crude like this:

<txp:linklist wraptrag="ol" class="bibliography" break="li">
  <txp:link_description />, <txp:if_link_url><txp:link_url />, </txp:if_link_url>accessed <txp:link_date />
</txp:linklist>

In other words:

  • [Last name, First name, ‘Title’, Source, YYYY], [https:doi.org/id], accessed on [dd month yyyy]

Unfortunately, I can’t use the Title field because I can’t insert it between the author name and source details with core functionality (or at least not that I know zip about).

But I can use a sort value in pattern ‘Last name, YYYY’, which more or less ensures a list in alphabetical-then-date order.

If I had even just one extra free-data field (e.g. ‘Datatype 1’, <txp:link_data1 />), I would use that for author and then add author data and title to the start of the output:

<txp:linklist wraptrag="ol" class="bibliography" break="li">
  <txp:link_data1 />, <txp:link_name />, <txp:link_description />, <txp:link_url />, accessed <txp:link_date />
</txp:linklist>

But if we go that far, might as well add a few more for sake of granularity and flexibility:

  • Title: [Title] (<txp:link_name />)
  • Sort value: ‘Last Name, YYYY
  • URL: [URL] (<txp:link_url />) needs to be conditional
  • Category: TBD
  • Publish date: [accessed DATE] (<txp:link_date />)
  • Publish time: Not used
  • Description: [Source] (<txp:link_description />)
  • Datatype 1: <txp:link_data1 />
  • Datatype 2: <txp:link_data2 />
  • Datatype 3: <txp:link_data3 />
  • Datatype 4: <txp:link_data4 />
  • Datatype 5: <txp:link_data5 />

The additional fields would also all need to be usable on a conditional basis.

And, no, I do not want to Frankenstein a bibliography out of articles. Trying to make better use of links here, is the point.

Last edited by Destry (2024-01-12 16:23:14)

Offline

#2 2020-06-22 16:34:31

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

Re: Bibliography management

To add fields you’d need a small custom-field-like plugin (jakob has one for images and files, which could be adapted).

You can make the URL conditional using <txp:evaluate> with the test attribute to check if the give tag returns anything:

<txp:linklist wraptrag="ol" class="bibliography" break="li">
   <txp:link_description />, <txp:evaluate test="link_url"><txp:link_url />, </txp:evaluate>accessed <txp:link_date />
</txp:linklist>

Last edited by Bloke (2020-06-22 16:35:56)


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

#3 2020-06-22 16:35:54

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

Re: Bibliography management

If I want to use the otherwise useless links panel to create

it’s very useful to me:)
Variables are your friend. The hashtag (#) is there as in 4.7, empty links were not recognised. I did not check if the functionality changed.

<txp:linklist wraptrag="ol" class="bibliography" break="li">
<txp:link_description />, 
<txp:variable name="haslink" value='<txp:link_url />' /> 
<txp:if_variable name="haslink" value="#"> 
<txp:link_name escape="" /> 
<txp:else /> 
<a href="<txp:link_url />"><txp:link_name escape="html" /></a> 
</txp:if_variable>, 
accessed <txp:link_date />
</txp:linklist>

> Edit Stef was quicker with a more economical solution too:)

Last edited by colak (2020-06-22 16:46:48)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#4 2020-06-22 19:04:42

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: Bibliography management

Bloke wrote #323909:

To add fields you’d need a small custom-field-like plugin (jakob has one for images and files, which could be adapted).

I have jcr_link_custom already but it adds just one custom field to the links panel for the moment. If you’re seriously interested in this, I could upgrade it have multiple fields. I have since updated this to work with up to 5 custom fields.

In conjunction with txp:evaluate like Stef mentioned, or also using the wraptag attributes you can display information or not as the case may be. The former is good for when you have a lot of complex output dependent on whether a tag exists, the latter is good practice in general to avoid outputting any html when a tag/field has no value.

EDIT: updated infos about the state of the plugin.


TXP Builders – finely-crafted code, design and txp

Offline

#5 2020-06-22 20:02:16

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

Re: Bibliography management

colak wrote #323910:

it’s very useful to me:)

In this site it won’t be, is what I meant. Though in 16 years, I‘ve never really used the Links panel much, and the Files panel never. I’ve always been an outlier, though.

Bloke wrote #323909:

You can make the URL conditional using <txp:evaluate>

Noice. That problem… Not a problem, then.

jakob wrote #323916:

I have jcr_link_custom already but it adds just one custom field to the links panel for the moment.

One field would be great! I could use that for author(s) and get the Title field back in the bargain. The middle [source] stuff will likely be variable enough across types that editing them in the description field is probably prudent for now.

Hook me up!

Last edited by Destry (2020-06-22 20:04:48)

Offline

#6 2020-06-23 13:40:24

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

Re: Bibliography management

I think these ‘not registered’ warnings can be safely ignored in ‘debugging’ mode, if I remember correctly?

Textpattern Notice: jcr_link_custom tag is not registered while parsing form bibliography on page default

Offline

#7 2020-06-23 13:55:21

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

Re: Bibliography management

Yeah, you can ignore those or patch them.

You don’t need the surrounding if() { ... } wrapper if you’re on Textpattern post-4.6.x since the class will always exist:

Txp::get('\Textpattern\Tag\Registry')
	->register('abc_tag_does_this')
	->register('abc_tag_does_that')
	...
;

Last edited by Bloke (2020-06-23 13:56:14)


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

#8 2020-06-23 14:01:48

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: Bibliography management

Ah yes. Stef’s solution is spot on. I’ll try and it give it an overhaul this evening.


TXP Builders – finely-crafted code, design and txp

Offline

#9 2020-06-24 11:59:20

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

Re: Bibliography management

So this is working good so far:

<txp:linklist wraptag="ol" class="biblio" break="li">
<txp:jcr_link_custom />, 
<txp:link_name escape="tidy, textile" />, 
<txp:link_description escape="tidy, textile" />, 
<txp:evaluate test="link_url"><txp:link_url />, </txp:evaluate>
accessed <txp:link_date />
</txp:linklist>

But I realized that, for consistency’s sake, I’ll need to use the Title field (i.e. link_name) only for article/chapter-like titles, not the actual names of books, etc, which would still be better addressed in the Description field. 1 Thus a conditional field. And, when used for a given source, the title would be surrounded with single quotation marks (à la OSM2 style), and it would be best to add those via surrounding HTML, not as cruft in the field.

Basing it on Bloke’s suggestion for link_url, I tried this using evaluate:

<txp:linklist wraptag="ol" class="biblio" break="li">
<txp:jcr_link_custom />, 
&#x2018<txp:evaluate test="link_name"><txp:link_name escape="tidy, textile" />&#x2019, </txp:evaluate> 
<txp:link_description escape="tidy, textile" />, <txp:evaluate test="link_url"><txp:link_url />, </txp:evaluate>
accessed <txp:link_date />
</txp:linklist>

And that works, but only when a Title value exists. If not, Txp outputs a single quotation mark even if the field is empty. I’m guessing it’s because it is a required field that is being negotiated in the snippet, but I’m not sure what can be done, if anything.

I then thought I might use the jcr_link_custom tag for such ‘titles’ and use the Txp link’s Title field for author names, but, besides being very non-intuitive, it also would not solve the problem because you could potentially have a source that has no declared author in that lead position, thus end up with a single quotation mark again.

Any way to to use the Title field as suggested above even if the field is empty, without getting the single quot mark?

1 Making me think an extension of the jcr_link_custom plugin might be worthwhile, but I could explore that on a more personalized basis if JCR didn’t mind me calling the result dry_bib ;) Otherwise, an extension of jcr_link_custom for an additional 3 to 5 generic free-use fields could be handy.
2. Oxford Style Manual

Last edited by Destry (2020-06-24 12:02:15)

Offline

#10 2020-06-24 12:09:09

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

Re: Bibliography management

Destry wrote #323962:

Basing it on Bloke’s suggestion for link_url, I tried this using evaluate:

<txp:linklist wraptag="ol" class="biblio" break="li">...

And that works, but only when a Title value exists. If not, Txp outputs a single quotation mark even if the field is empty.

Why do you put the opening mark outside evaluate? It could even be something like

<txp:linklist wraptag="ol" class="biblio" break="li">
<txp:jcr_link_custom />, 
<txp:link_name escape="tidy, textile" wraptag="&#x2018<+>&#x2019, " />
<txp:link_description escape="tidy, textile" />, <txp:link_url wraptag="<+>, " />
accessed <txp:link_date />
</txp:linklist>

Offline

#11 2020-06-24 12:11:04

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

Re: Bibliography management

Destry wrote #323962:

that works, but only when a Title value exists. If not, Txp outputs a single quotation mark even if the field is empty.

Uhhh, shouldn’t you put the opening quotation mark inside the conditional (<txp:evaluate>)?

<txp:evaluate test="link_name">&#x2018<txp:link_name escape="tidy, textile" />&#x2019, </txp:evaluate>

EDIT: too slow, and I forgot about wraptag’s superpowers! Do what etc suggests.

Last edited by Bloke (2020-06-24 12:13:01)


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 2020-06-24 12:20:01

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

Re: Bibliography management

etc wrote #323963:

Why do you put the opening mark outside evaluate?

Because I don’t know WTF I’m doing in tag voodoo.

But, this, wraptag="&#x2018<+>&#x2019, ", does help me finally understand at least one way <+> can be used. Thanks. ;)

However, I still have the problem of not being able to save a link without something in the Title field, and as I was saying above, I won’t always need a title value, only on a conditional basis.

Last edited by Destry (2020-06-24 12:22:03)

Offline

Board footer

Powered by FluxBB