By: Anthony
Date: 2014-09-30
Time: 22:09
|
File ExistsIs there a way to check if a file exists when template is shown and if file does not exist, then to not display a section of the template. For example:
The filename is stored in DB along with other data, so when TBS does the merge, I need to grab that filename and check if file actually exists. If not, I want the div to be deleted. |
||
By: Skrol29
Date: 2014-10-01
Time: 01:35
|
Re: File ExistsHi,
If you are using a MergeBlock() then you can use an "nodata" custom function in order to build a calculated column saying if the file exists (using PHP function file_exists()). Otherwise you can use an "onformat" function, or even use a PHP variable saying if the file exists. |
||
By: Anthony
Date: 2014-10-01
Time: 20:05
|
Re: File ExistsSo, I am getting a field value from the database when page loads, and this field represents a filename that is suppose to be on server. How do I pass that field name to the custom function and either keep or remove html tag. My custom function will fun php file_exists to see if an actual file is on the server and if not, have the div to be removed by TBS. There will or should always be a value for article_block.file but there may or may not be an actual file, so I don't need it to display when not present.
|
||
By: Skrol29
Date: 2014-10-02
Time: 00:01
|
Re: File ExistsHi,
It is described in the documentation here: http://www.tinybutstrong.com/manual.php#html_field_prm_onformat |
||
By: Anthony Brock
Date: 2014-10-03
Time: 15:02
|
Re: File ExistsWell, I can get the custom function to be called, but it does not appear that the value I want to return gets returned. Perhaps there is something I still don't understand about how it is suppose to work.
HTML
PHP
|
||
By: Anthony Brock
Date: 2014-10-03
Time: 17:10
|
Re: File ExistsOk, I discovered that I don't use return $CurrVal, but simply use $CurVal = 'desired value'. However, I suppose that TBS will not process any variables in the function and apply to html such as the $divExtra variable.
|
||
By: Skrol29
Date: 2014-10-04
Time: 10:52
|
Re: File ExistsThat is correct. It is specified in the documentation.
The character "&" added to the variables in the function declaration (such as &$CurrVal) means that the values are passed by references. This means when you change the value of $CurrVal the this value still remain outside of the function. This is the way "onformat" functions works to modify the current value. |