Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#61 2017-07-25 09:33:14

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Textpattern evaluation (dis)abilities

OK, another question, using <txp:evaluate> how can I test if a file category has an entry or not? And provide one action for yes, one for no? See here for history but I’m sure it’d be cleaner to do with the evaluate tag than the suggestions there?

Offline

#62 2017-07-25 09:57:27

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

Re: Textpattern evaluation (dis)abilities

philwareham wrote #306427:

OK, another question, using <txp:evaluate> how can I test if a file category has an entry or not? And provide one action for yes, one for no?

If this syntax is still the current state of play, then I guess it would be:

<!-- outputs file download list if any exist or a message if not -->
<txp:evaluate test="file_download_list">
    <txp:file_download_list category="current-beta-release" limit="1" break="" wraptag="" sort="downloads desc" />
<txp:else />
    <p>No beta releases available at present.</p>
</txp:evaluate>

TXP Builders – finely-crafted code, design and txp

Offline

#63 2017-07-25 10:15:49

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Textpattern evaluation (dis)abilities

jakob wrote #306428:

If this syntax is still the current state of play, then I guess it would be…

Great, that works just as I wanted. Thank you very much!

Offline

#64 2017-07-25 14:29:42

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Textpattern evaluation (dis)abilities

Bloke wrote #306418:

Sure:

<txp:evaluate query='<txp:image_info type="w" />div2' />...

Just one more question if may: can the above be adjusted so that the value is rounded to the nearest whole number (i.e. if the original 2x image was 481 pixels high the 1x image would be shown as 240.5 when in reality it is 241).

Offline

#65 2017-07-25 14:36:07

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

Re: Textpattern evaluation (dis)abilities

Just one more question if may: can the above be adjusted so that the value is rounded to the nearest whole number

Just guessing, but could ceiling be of help here?


TXP Builders – finely-crafted code, design and txp

Offline

#66 2017-07-25 15:59:02

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

Re: Textpattern evaluation (dis)abilities

jakob beat me to it, but:

<txp:evaluate query='ceiling(<txp:image_info type="w" />div2)' />

should work.


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

#67 2017-07-25 16:04:40

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Textpattern evaluation (dis)abilities

Hurrah! ???

Is there anything you guys don’t know?!

Offline

#68 2020-02-26 01:42:07

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

Re: Textpattern evaluation (dis)abilities

I am trying to make a calculation in a shortcode (the variables passed are days, minutes, and seconds)

<txp::entry_meta_date days="7" hours="0" minutes="0" />

this is the shortcode

<txp:variable name="active_time" value='<txp:evaluate query='(<txp:yield name='days' /> * 86400) + (<txp:yield name='hours' /> * 3600) + (<txp:yield name='minutes' /> * 60)' />' />

"<txp:variable name="active_time" />"

"<txp:evaluate query='(<txp:yield name='days' /> * 86400) + (<txp:yield name='hours' /> * 3600) + (<txp:yield name='minutes' /> * 60)' />"

And this is the output:

<txp:variable name="active_time" value='604800' />

""

"604800"

Is there a way to set a variable using the output from txp:evaluate?

Offline

#69 2020-02-26 02:46:16

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: Textpattern evaluation (dis)abilities

I’m not saying I understand all this current yield stuff, and hence I’ve not proofread your code. But you’ve tags inside tags inside tags. So your apostrophes should be like that:

<txp:tag attribute='<txp:first_nested_level attribute=''<txp:second_nested_level />'' />' />

…and so on, for each nested level one more pair of surrounding single apostrophes. And normal double ones where single ones aren’t needed (where you’re not nesting), for better processing speed.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#70 2020-02-26 09:14:57

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

Re: Textpattern evaluation (dis)abilities

In this case I would use a container:

<txp:variable name="active_time" escape="tidy, integer">
   <txp:evaluate ... />
</txp:variable>

Saves all the quoting nonsense. Escape reference.

Last edited by Bloke (2020-02-26 09:17:42)


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

#71 2020-02-26 19:02:06

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

Re: Textpattern evaluation (dis)abilities

Thanks everyone. This does work.

<txp:variable name="active_time">
    <txp:evaluate query='(<txp:yield name='days' /> * 86400) + (<txp:yield name='hours' /> * 3600) + (<txp:yield name='minutes' /> * 60)' />
</txp:variable>

I was trying to figure out a way to duplicate the functionality of csb_if_newer_than

function csb_if_newer_than($atts, $thing) {
	global $thisarticle;

	extract(lAtts(array(
			'days'  => '0',
			'hours'  => '0',
			'minutes'  => '0'
		),$atts));

	$active_time = $days * 86400 + $hours * 3600 + $minutes * 60;

	return (time() - $thisarticle['posted'] < $active_time) ? parse(EvalElse($thing, true)) : parse(EvalElse($thing, false));
}

but I am not sure it can be done.

Offline

#72 2020-02-27 02:17:22

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

Re: Textpattern evaluation (dis)abilities

michaelkpate wrote #321941:

I was trying to figure out a way to duplicate the functionality of csb_if_newer_than

You can cheat with a partial solution. Create a shortcode Form called something like is_newer as follows:

<txp:php>
    global $thisarticle;

    $days = parse('<txp:yield name="days" default="0" />');
    $hours = parse('<txp:yield name="hours" default="0" />');
    $mins = parse('<txp:yield name="minutes" default="0" />');

    $active_time = $days * 86400 + $hours * 3600 + $mins * 60;

    echo parse('<txp:yield />', time() - $thisarticle['posted'] < $active_time);
</txp:php>

That could then be called like this:

<txp::is_newer hours="4" minutes="30">
   Article is newer than 4.5 hours!
</txp::is_newer>

The downside? I have no idea how to make it respond to <txp:else /> so it can process both true and false parts. All my tests failed so far. There’s probably a trick to it, but in the meantime this might get you moving in a good direction.


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

Board footer

Powered by FluxBB