Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#37 2021-05-13 19:22:24

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 220
Website

Re: Sort articles based on multiple dates defined in one custom_field

So article_custom has the ability to take every cf-name as an attribute an test some value against it?
Cool. But it is still not working.

When I use

<xsl:for-each select="h4">

instead of

<xsl:for-each select="h4[string()='{?search_month}']">

I get results. Sorry I do not have enough understanding about what happens in the xsl context to see any mistake – if there is any.

Offline

#38 2021-05-13 19:29:56

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

Re: Sort articles based on multiple dates defined in one custom_field

Is your search_month variable set (and sanitized) at this stage?

Offline

#39 2021-05-13 19:31:56

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 220
Website

Re: Sort articles based on multiple dates defined in one custom_field

Yes it is. Its value is “2021-05”. So I guess it should show all my current test events that I put in some dates in May.

Offline

#40 2021-05-13 19:35:16

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

Re: Sort articles based on multiple dates defined in one custom_field

Have you added specials="content" attribute to <txp:etc_query />? And what happens if you set

<xsl:for-each select="h4[string()='2021-05']">

Offline

#41 2021-05-13 19:52:07

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 220
Website

Re: Sort articles based on multiple dates defined in one custom_field

I have added specials="content", yes.

Here comes my full code. I changed some variables and parameters a bit but without the [string()='{?search_month}'] bit it works (just no month-sorting then)

<txp:variable name="eventslist">
<txp:article_custom wraptag="article" vorstellungen='%<txp:variable name="search_month" />%' section='<txp::sec n="spielplan"/>'><!-- add attributes as needed -->
<txp:etc_query data='<txp::connector_vorstellungen />' markup="ini">

<h4><txp:variable name="mydate" output value="{datum?}"/></h4>

	<div class="card card-body mb-5">
		<div class="row">
			<div class="col-md-2">
				<txp:if_different><div id='d_{datum?}'>{datum?}</div>
				</txp:if_different>
			</div>
			<div class="col-md-2">
				{zeit?}

			</div>
			<div class="col-md-6">
				<h2><txp:title /> </h2>
				<a href="{link?}" class="btn btn-primary">Tickets</a> ({ort?})
			</div>
		</div>

	</div>


</txp:etc_query>
</txp:article_custom>
</txp:variable>

<txp:etc_query specials="content" data='<txp:variable name="eventslist" />' >
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:txp="https://www.textpattern.com">
<xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes" />
<xsl:template match="article">
<xsl:for-each select="h4[string()='{?search_month}']">
		<xsl:sort select="." order="ascending" />
		<txp:if_different><xsl:copy-of select="." /></txp:if_different>
		<xsl:copy-of select="following-sibling::div[1]" />
	</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
</txp:etc_query>

And what happens if you set
<xsl:for-each select=“h4[string()=‘2021-05’]”>

No output, sorry.

Last edited by demoncleaner (2021-05-13 19:57:26)

Offline

#42 2021-05-13 20:03:51

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

Re: Sort articles based on multiple dates defined in one custom_field

Ah, sorry, my bad. I have forgotten that your dates include days too. Try first

<xsl:for-each select="h4[starts-with(., '2021-05')]">

and then

<xsl:for-each select="h4[starts-with(., '{?search_month}')]">

if it works. Here is a list of XPath functions you can use in etc_query.

Offline

#43 2021-05-13 20:08:04

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 220
Website

Re: Sort articles based on multiple dates defined in one custom_field

I was nasty and tried first

<xsl:for-each select="h4[starts-with(., '{?search_month}')]">

=P It works like a charm!!! (the other one as well)

Offline

#44 2021-05-13 20:14:14

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

Re: Sort articles based on multiple dates defined in one custom_field

That’s great. Strange that your if_variable attempt produced duplicates (if I get it right), but Ende gut – alles gut!

Offline

#45 2021-05-13 20:23:45

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 220
Website

Re: Sort articles based on multiple dates defined in one custom_field

Ende gut – alles gut!

Ganz genau! =)

I hope that was the biggest task of my project. I am so glad it works now.
Thanks again for your time and help.

Offline

Board footer

Powered by FluxBB