Jump to:

23007 Posts in 11866 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » image.php - getTag , title problems

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

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

Page: 1
Go to End
Author Topic: 1887 Views
  • AlknicTeos
    Avatar
    Community Member
    5 Posts

    image.php - getTag , title problems Link to this post

    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\" />";

  • juandavidgc
    Avatar
    Community Member
    36 Posts

    Re: image.php - getTag , title problems Link to this post

    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 )

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

  • AlknicTeos
    Avatar
    Community Member
    5 Posts

    Re: image.php - getTag , title problems Link to this post

    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 ?

  • Benedikt
    Avatar
    Community Member
    16 Posts

    Re: image.php - getTag , title problems Link to this post

    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.

  • DsX
    Avatar
    Community Member
    178 Posts

    Re: image.php - getTag , title problems Link to this post

    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.

    1887 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.