Skrol29 / tinybutstrong

TBS is a PHP template engine for pro and beginners. Only 1 class with few methods properties, but it can do may things for any text templates, including HTML and XML. The only engine that enables W3C compliant templates. It has many plugins including OpenTBS.
http://www.tinybutstrong.com
60 stars 18 forks source link

Parameter to detect if field exists? #18

Closed bodywatch-it closed 4 years ago

bodywatch-it commented 4 years ago

I'm trying to apply a block with data that may or may not have a given field set. I can use a conditional to display things or not with when , but this causes an error (naturally) when it's evaluating the conditional. I can apply noerr at the template level (I think?), but I'd rather it be done at the block level (or possibly field level). Is this possible, or should I try making a empty_if_missing() function at the passed-in-class object thing?

Skrol29 commented 4 years ago

Yes is it possible. See parameter noerr for fields.

https://www.tinybutstrong.com/manual.php#html_field_prm_noerr

bodywatch-it commented 4 years ago

I must be doing something wrong then? 😕

[data;noerr=true;block=landmark;when [data.AS_FPTXYZ] != '']

Is this out of order or otherwise incorrect?

Skrol29 commented 4 years ago

[data;block=landmark;when '[data.AS_FPTXYZ;noerr]' != '']

or

[data.AS_FPTXYZ;noerr;block=landmark;magnet=landmark]

bodywatch-it commented 4 years ago

Awesome, thanks!