Categories > TinyButStrong general >

Conditional - if set add to the string

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Chris Fordham
Date: 2007-07-23
Time: 07:38

Conditional - if set add to the string

Say I have a php variable that could be set or may not be:

$page['document_title'] = 'Trees and shrubs of my garden';

In my template i have:

<title>My site - [var.page.document_title]</title>

When there is no $page['document_title] , of course I don't want to display the hyphon and spaces.

<title>My site[var.page.document_title]</title>

But how do I put in the ' - ' if the variable is set without doing a server side onformat= function? ie. i only want to add ' - ' to the start of ['var.page.document_title] if it is set.
By: Skrol29
Date: 2007-07-23
Time: 10:25

Re: Conditional - if set add to the string

<title>My site [var.page.document_title;if [val]!='' then '- '][var.page.document_title]</title>

Or (not tested):

<title>My site [var.page.document_title;if [val]!='' then - [val]</title>

But the best is to add the hyphon in the PHP variable.
By: Chris Fordham
Date: 2007-07-24
Time: 08:22

Re: Conditional - if set add to the string

You are a legend as usual, Skrol29.

Here is the one that seems best from your example/s:

<title>My Title Prefix[var.page.document_title;if [val]!='';then ' - [val]';noerr]</title>

It might be useful to put an example like this in the Examples or Manual page.
I guess its called conditional text substitution or something.
By: Chris Fordham
Date: 2007-07-24
Time: 08:23

Re: Conditional - if set add to the string

Preformatted:

<title>My Title Prefix[var.page.document_title;if [val]!='';then ' - [val]';noerr]</title>