Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 Yesterday 08:23:58

abu
New Member
From: Switzerland
Registered: 2025-04-03
Posts: 7
GitHub GitLab Mastodon

Using article_custom with attribute month

I detected that

<txp:article_custom section='articles' month='2025-07' />

works as documented, but putting the month in a variable

<txp:article_custom section='articles' month="<txp:variable name='d' />" />

doesn’t.

What is the official or recommended way to use the month attribute with variable values?
Are there any usage examples available?

Offline

#2 Yesterday 11:22:41

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

Re: Using article_custom with attribute month

Try switching the quotes around. Use single quotes to denote “process the contained tag and puts its result here”, otherwise double quotes for normal attributes.

<txp:article_custom section="articles" month='<txp:variable name="d" />' />

And your variable d should take the form YYYY or YYYY-MM. You can use the format attribute to output dates in other formats using strftime notation, e.g. format="%Y-%m"


TXP Builders – finely-crafted code, design and txp

Offline

#3 Yesterday 16:22:34

abu
New Member
From: Switzerland
Registered: 2025-04-03
Posts: 7
GitHub GitLab Mastodon

Re: Using article_custom with attribute month

Thanks for your prompt reply. I have tested all possible variations before. Out of the box, your proposal didn’t work either.

The problem is/was that I defined the variable formatted using multiple lines.

<txp:variable name="d">
   ...
</txp:variable>

Thus the variable content was surrounded with some whitespace and linefeed (?) chars.

Two solutions:

a) Write the definition as a one-liner; avoid any whitespace.

<txp:variable name="d">...</txp:variable>

b) Add a trim attribute on insertion.

<txp:article_custom section="articles" month='<txp:variable name="d" trim="/[\n\r\t ]/" />' />

Everything is working as expected now.

Huge thanks!

Offline

#4 Yesterday 17:00:34

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

Re: Using article_custom with attribute month

Hmm, that’s annoying that linebreaks break strtotime(), thanks for the hint. Can anyone see any drawback of incorporating a cleanup into core?

Offline

#5 Yesterday 22:09:57

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

Re: Using article_custom with attribute month

Glad you got it working, and it sounds like you know what you’re doing, and found your solution.


TXP Builders – finely-crafted code, design and txp

Offline

#6 Today 00:04:16

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

Re: Using article_custom with attribute month

Doesn’t adding trim.during variable definition work?

<txp:variable name="d" trim>
   ...
</txp:variable>
<txp:article_custom section="articles" month='<txp:variable name="d" />' />

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

#7 Today 06:11:11

abu
New Member
From: Switzerland
Registered: 2025-04-03
Posts: 7
GitHub GitLab Mastodon

Re: Using article_custom with attribute month

Yes, you’re right. This works either, thank you.

Offline

Board footer

Powered by FluxBB