Page 1 of 1

Display image in table view

Posted: 2023-10-30 04:48
by jaddison
Hi
I have a table that has a field 'ImageURL', that has a link to an image.
I want this field to display as an image in table view.
I have tried to achieve this in the table's php file in the hooks folder, seed code.
I know there will be a problem with img src...

Code: Select all


	function Person_init(&$options, $memberInfo, &$args) {
	// get the original fields array
	$oldFields = $options->QueryFieldsTV;
	
	foreach($oldFields as $field => $title){
		// find the field that we need to customise
		if($field == 'Person.ImageURL'){
			// apply custom sql formatting to the field
			$modField = "<img src='Person.ImageURL'>";
			$newFields($modField) = $title;
		}else{
			// for other fields, keep them unchanged
			$newFields($field) = $title;
		}
	
	}
		//now apply the modified fields
		$options->QueryFieldsTV = $newFields;

		return TRUE;
	}

[code]

thanks
John

Re: Display image in table view

Posted: 2023-10-30 07:06
by jsetzer
Can you please inspect the final HTML code in your browser's developer tools.

The <img/> tag may have been removed for security reasons (XSS vulnerability).

If this is the case, you could replace the imageURL-string by an <img/>-tag using javascript in hooks/TABLENAME-tv.js.

Re: Display image in table view

Posted: 2023-10-31 00:29
by jaddison
thanks for the reply js.
there was an error in my code $newFields() should have square brackets $newFields[].
You were correct the <img> tag does not show in the developer tools...
to use the hooks/TABLENAME-tv.js file I have no idea. I have to create it first then?
John

Re: Display image in table view

Posted: 2023-10-31 03:05
by jaddison
sorted it out. Used the Person_TemplateTV.html file.
<%%SELECT%%><img src="<%%VALUE(ImageURL)%%>"style=height:60px;><%%ENDSELECT%%>
works perfect. Only problem is I have to amend the template file every time after I regenerate the project files for upload.