Display image in table view

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
jaddison
Veteran Member
Posts: 34
Joined: 2020-06-12 12:44

Display image in table view

Post by jaddison » 2023-10-30 04:48

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

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1817
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Display image in table view

Post by jsetzer » 2023-10-30 07:06

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.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

jaddison
Veteran Member
Posts: 34
Joined: 2020-06-12 12:44

Re: Display image in table view

Post by jaddison » 2023-10-31 00:29

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

jaddison
Veteran Member
Posts: 34
Joined: 2020-06-12 12:44

Re: Display image in table view

Post by jaddison » 2023-10-31 03:05

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.

Post Reply