Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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
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
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
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
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
Re: Using article_custom with attribute month
Yes, you’re right. This works either, thank you.
Offline