Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-04-01 17:11:57

Iki
Member
From: New Hampshire
Registered: 2008-05-26
Posts: 22

How many days until a date - php snippet in page

I’ve got a bit of code I was using on my site index prior to loading up TXP today. I put it into my default page template, using the <txp:php tags, but it’s quitting in the middle of the line and then just printing the rest on the web page.

 <notextile>
<txp:php echo (new DateTime('2021-05-03'))->diff(new DateTime())->days; /txp:php>
</notextile>

shows up on the site as
diff(new DateTime())->days; /txp:php> days left

I tried to escape the side bracket but it didn’t help. Any help here is greatly appreciated, I’m super rusty at this and have been away from TXP for a few years!

Thanks!


“Some days, even my lucky rocketship underpants don’t help.” — Calvin, Calvin & Hobbes

Offline

#2 2021-04-01 17:34:29

Iki
Member
From: New Hampshire
Registered: 2008-05-26
Posts: 22

Re: How many days until a date - php snippet in page

Wow, that was stupid… gotta close those txp tags. It HAS been a long time!

Sorry!


“Some days, even my lucky rocketship underpants don’t help.” — Calvin, Calvin & Hobbes

Offline

#3 2021-04-01 17:34:58

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

Re: How many days until a date - php snippet in page

Iki wrote #329631:

I’ve got a bit of code I was using on my site index prior to loading up TXP today. I put it into my default page template, using the <txp:php tags, but it’s quitting in the middle of the line and then just printing the rest on the web page.

<notextile>...

shows up on the site as
diff(new DateTime())->days; /txp:php> days left

I tried to escape the side bracket but it didn’t help. Any help here is greatly appreciated, I’m super rusty at this and have been away from TXP for a few years!

Thanks!

Hi Iki,

If the code resides in a template/page then you do not need the <notextile /> tag. If it resides in an article try ==<txp:php> echo (new DateTime('2021-05-03'))->diff(new DateTime())->days; </txp:php>==

Also… The php tags in your code are not closed. it should be

<notextile>
<txp:php>echo (new DateTime('2021-05-03'))->diff(new DateTime())->days; </txp:php>
</notextile>

>Edit I see you fixed it as I was writing. It’s the forum’s magical ability:)

Last edited by colak (2021-04-01 17:36:34)


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 2021-04-01 19:39:14

Iki
Member
From: New Hampshire
Registered: 2008-05-26
Posts: 22

Re: How many days until a date - php snippet in page

These forums are magical! Even so, I appreciate you putting the thought and effort into replying. I’ll take all the advice I can get!

Thanks!


“Some days, even my lucky rocketship underpants don’t help.” — Calvin, Calvin & Hobbes

Offline

#5 2021-04-01 19:40:18

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: How many days until a date - php snippet in page

This can also be done with etc_date if you prefer to go the plugin route.

Offline

#6 2021-04-01 20:38:24

Iki
Member
From: New Hampshire
Registered: 2008-05-26
Posts: 22

Re: How many days until a date - php snippet in page

michaelkpate wrote #329637:

This can also be done with etc_date if you prefer to go the plugin route.

Thanks for the info! I’m not quite ready to go for plugins yet, I’m still trying to figure out what does what to who in the interface. I think maybe I should have loaded a theme when I installed so there’d be something for me to look at instead of zero blank.


“Some days, even my lucky rocketship underpants don’t help.” — Calvin, Calvin & Hobbes

Offline

#7 2021-04-01 20:39:20

Iki
Member
From: New Hampshire
Registered: 2008-05-26
Posts: 22

Re: How many days until a date - php snippet in page

Man I shouldn’t have looked at that plugin… ideas are hatching in my head :)


“Some days, even my lucky rocketship underpants don’t help.” — Calvin, Calvin & Hobbes

Offline

Board footer

Powered by FluxBB