The tut missing "how to add" very basic and important element:
1)Alt (very important! for SEO & accessibility & valid code) *in file manger "alt" is missing so i use "description"
2)Width and height
3)Title
.
Here are a few examples:
- display an image with class, title, alt, height, and width
// get the attribute file object$img=$c->getAttribute('test_image');if(is_object($img)){// get the "tall_thumbnail" thumbnail type$type= \Concrete\Core\File\Image\Thumbnail\Type\Type::getByHandle('tall_thumbnail');// getThumbnailUrl() is passed $type->getBaseVersion()// - the base version is the thumbnail created from the specified thumbnail dimensions// - if there is no thumbnail of that type, the path of the original image is used// getThumbnailUrl() returns the absolute path of the image$src=$img->getThumbnailURL($type->getBaseVersion());// - if there is no title, then the filename is used// - concatenation operator on a single lineecho'<img src="'.$src.'" class="monkeypants" title="'.$img->getTitle().'" alt="'.$img->getTitle().'" width="'.$type->getWidth().'" height="'.$type->getHeight().'" >';// - expanded variables, functions, and methods using double quotesecho"<img src=\"$src\" class=\"monkeypants\" title=\"{$img->getTitle()}\" alt=\"{$img->getTitle()}\" width=\"{$type->getWidth()}\" height=\"{$type->getHeight()}\">";
// get the attribute file object$img=$c->getAttribute('test_image');if(is_object($img)){// get the "tall_thumbnail" thumbnail type$type= \Concrete\Core\File\Image\Thumbnail\Type\Type::getByHandle('tall_thumbnail');// getThumbnailUrl() is passed $type->getBaseVersion()// - the base version is the thumbnail created from the specified thumbnail dimensions// - if there is no thumbnail of that type, the path of the original image is used// getThumbnailUrl() returns the absolute path of the image$src=$img->getThumbnailURL($type->getBaseVersion());// - if there is no title, then the filename is used// - concatenation operator on a single lineecho'<img src="'.$src.'" class="monkeypants" title="'.$img->getTitle().'" alt="'.$img->getTitle().'" width="'.$type->getWidth().'" height="'.$type->getHeight().'" >';// - expanded variables, functions, and methods using double quotesecho"<img src=\"$src\" class=\"monkeypants\" title=\"{$img->getTitle()}\" alt=\"{$img->getTitle()}\" width=\"{$type->getWidth()}\" height=\"{$type->getHeight()}\">";// Example output:// <img src="http://localhost/concrete5/application/files/thumbnails/tall_thumbnail/5414/5102/4445/Strawberry-Red-Velvet-Cupcakes1.jpg" class="monkeypants" title="delicious strawberry red velvet cupcakes" alt="delicious strawberry red velvet cupcakes" width="300" height="600">}
- display an image with class, title, alt, height, and width using HTMLObject
// get the attribute file object$img=$c->getAttribute('test_image');if(is_object($img)){// get the "tall_thumbnail" thumbnail type$type= \Concrete\Core\File\Image\Thumbnail\Type\Type::getByHandle('tall_thumbnail');// getThumbnailUrl() is passed $type->getBaseVersion()// - the base version is the thumbnail created from the specified thumbnail dimensions// - if there is no thumbnail of that type, the path of the original image is used// getThumbnailUrl() returns the absolute path of the image$src=$img->getThumbnailURL($type->getBaseVersion());// HtmlObject\Image is part of the HTMLObject vendor library and is used to create the img element// C:\xampp\htdocs\concrete5\concrete\vendor\anahkiasen\html-object\src\HtmlObject\Image.php// - if there is no title, then the filename is usedecho HtmlObject\Image::create($src)->class('my-img-class')->title($img->getTitle())->alt($img->getTitle())->width($type->getWidth())->height($type->getHeight());// Example output:
// get the attribute file object$img=$c->getAttribute('test_image');if(is_object($img)){// get the "tall_thumbnail" thumbnail type$type= \Concrete\Core\File\Image\Thumbnail\Type\Type::getByHandle('tall_thumbnail');// getThumbnailUrl() is passed $type->getBaseVersion()// - the base version is the thumbnail created from the specified thumbnail dimensions// - if there is no thumbnail of that type, the path of the original image is used// getThumbnailUrl() returns the absolute path of the image$src=$img->getThumbnailURL($type->getBaseVersion());// HtmlObject\Image is part of the HTMLObject vendor library and is used to create the img element// C:\xampp\htdocs\concrete5\concrete\vendor\anahkiasen\html-object\src\HtmlObject\Image.php// - if there is no title, then the filename is usedecho HtmlObject\Image::create($src)->class('my-img-class')->title($img->getTitle())->alt($img->getTitle())->width($type->getWidth())->height($type->getHeight());// Example output:// <img src="http://localhost/concrete5/application/files/thumbnails/tall_thumbnail/5414/5102/4445/Strawberry-Red-Velvet-Cupcakes1.jpg" alt="delicious strawberry red velvet cupcakes" class="my-img-class" title="delicious strawberry red velvet cupcakes" width="300" height="600">}
Code
Post Reply
Delete Post
You are allowed to delete your post for 5 minutes after it's posted.
This website stores cookies on your computer. These cookies are used to improve
your website experience and provide more personalized services to you, both on this website and through
other media. To find out more about the cookies we use, see our Privacy Policy.
Here are a few examples:
- display an image with class, title, alt, height, and width
- display an image with class, title, alt, height, and width using HTMLObject