Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

image.php - getTag , title problems


Go to End


5 Posts   3203 Views

Avatar
AlknicTeos

Community Member, 5 Posts

21 January 2010 at 1:30am

Edited: 21/01/2010 1:34am

Hello,

i hope this is the right place for my question/problem. I have searched for the problem, buf havent found anything therefor.

to the problem :
whenever an image gets resized, the $title will be empty (also for any other file $db ).

image.php // 2.3.4.

 
function getTag() {
		if(file_exists("../" . $this->Filename)) {
			$url = $this->URL();
			$title = ($this->Title) ? $this->Title : $this->Filename;
			
			return "<img src=\"$url\" alt=\"$title\" />";
		}
	}

when i call an image in the template with $image.setWidth(width:px), $title will get the Filename.

If its simple called with $image in the template, the correct title will be shown.

Well, anyone has an idea, how the correct $title can be accessed ?

(Also how i can make changes to File.php,Image.php effects it outside the sapphire folder? for easier maintenance with an update)

the goal would be something like that:

return "<img src=\"$url\" alt=\"$title\" title=\"$MyFileDescription\" />";

Avatar
juandavidgc

Community Member, 36 Posts

21 January 2010 at 8:54am

Hi AlknicTeos!

Wich "Title" would you like to show? Title of the page... or the name of the image file?

If you want to show Title of current page, you can put this code (I don't know if it's the right way but it works for me :P )

<% control Image %>
<% control SetWidth(100) %>
<img src="$URL"
<% end_control %>
<% end_control %>
alt="$Title" />

Avatar
AlknicTeos

Community Member, 5 Posts

21 January 2010 at 9:41pm

Edited: 21/01/2010 10:00pm

Well, i actually dont want the page title, but the file title.
Also its nice to see how controls can be used, there is still the same problem :)

<% control Image %>
<% control SetWidth(100) %>
<img src="$URL" alt="$Title" />
<% end_control %>
<% end_control %>

<% control Image %>
<img src="$URL" alt="$Title" />
<% end_control %>

you will see the difference again. in the first case the $title will be empty and in the second, the $title of the file.
I want to access the db in
file.php
static $db = array(
"Name" => "Varchar(255)",
"Title" => "Varchar(255)",
"Filename" => "Varchar(255)",
"Content" => "Text",
"Sort" => "Int"
);

... for even resized images. Is it easily possible to get the original Filename of a resized image?

Thanks juandavidgc, maybe anyone else has another idea ?

Avatar
Benedikt

Community Member, 16 Posts

8 February 2010 at 10:27pm

Edited: 08/02/2010 10:27pm

I had the same problem and the partial solution above brought me to the following:

<% control Newspic %>
<% control SetWidth(150) %><img src="$URL" <% end_control %> alt="$Title" />
<% end_control %> 

Works fine for me. :)

Avatar
DsX

Community Member, 178 Posts

1 October 2010 at 7:28am

I have not tested, but I believe this should work:

<% control Image %>
<% control SetWidth(100) %>
<img src="$URL" alt="$Top.Title" />
<% end_control %>
<% end_control %>

One thing is that you 'should' get the title from the non-resized image, this may or may not work for you.